diff options
author | cvs2svn | 2002-09-26 12:16:15 +0000 |
---|---|---|
committer | cvs2svn | 2002-09-26 12:16:15 +0000 |
commit | 7175e6a0fca90230236785e19fc325d453c946ee (patch) | |
tree | 447e66fd7c58b9dec14ceb6f53540c6829b2c80a | |
parent | 7f6a4cbc7d30af66a3e3188ff65e7b61b265479d (diff) | |
download | eclipse.platform.text-TC_TOC.tar.gz eclipse.platform.text-TC_TOC.tar.xz eclipse.platform.text-TC_TOC.zip |
This commit was manufactured by cvs2svn to create branch 'TC_TOC'.TC_TOC
Sprout from master 2002-09-26 12:16:14 UTC Kai Maetzel <kmaetzel> 'cleanup'
Delete:
org.eclipse.jface.text/.classpath
org.eclipse.jface.text/.cvsignore
org.eclipse.jface.text/.project
org.eclipse.jface.text/build.properties
org.eclipse.jface.text/plugin.properties
org.eclipse.jface.text/plugin.xml
org.eclipse.jface.text/scripts/exportplugin.xml
org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractHoverInformationControlManager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractInformationControlManager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultAutoIndentStrategy.java
org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.java
org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java
org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultUndoManager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentAdapter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoIndentStrategy.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapterExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IEventConsumer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTarget.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreator.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkRegionTarget.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkSelection.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHover.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextInputListener.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextListener.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTarget.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTargetExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IViewportListener.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeper.java
org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java
org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.properties
org.eclipse.jface.text/src/org/eclipse/jface/text/MarkSelection.java
org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java
org.eclipse.jface.text/src/org/eclipse/jface/text/TextAttribute.java
org.eclipse.jface.text/src/org/eclipse/jface/text/TextEvent.java
org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java
org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java
org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewerHoverManager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/Helper.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistProcessor.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistant.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformation.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidator.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java
org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java
org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java
org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java
org.eclipse.jface.text/src/org/eclipse/jface/text/information/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationDamager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegionQueue.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategyExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/MonoReconciler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPredicateRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IToken.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ITokenScanner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWordDetector.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/NumberRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedDamagerRepairer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordPatternRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordRule.java
org.eclipse.jface.text/src/org/eclipse/jface/text/rules/package.html
org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationColumn.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/CompositeRuler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHover.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModel.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRuler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerColumn.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerExtension.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfo.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java
org.eclipse.jface.text/src/org/eclipse/jface/text/source/package.html
org.eclipse.search/.classpath
org.eclipse.search/.cvsignore
org.eclipse.search/.project
org.eclipse.search/about.html
org.eclipse.search/build.properties
org.eclipse.search/buildnotes_search.html
org.eclipse.search/doc/hglegal.htm
org.eclipse.search/doc/hglegal2002.htm
org.eclipse.search/doc/ngibmcpy.gif
org.eclipse.search/doc/ngibmcpy2002.gif
org.eclipse.search/doc/org_eclipse_search.html
org.eclipse.search/doc/org_eclipse_search_searchPages.html
org.eclipse.search/doc/org_eclipse_search_searchResultSorters.html
org.eclipse.search/icons/full/clcl16/search_goto.gif
org.eclipse.search/icons/full/clcl16/search_history.gif
org.eclipse.search/icons/full/clcl16/search_next.gif
org.eclipse.search/icons/full/clcl16/search_prev.gif
org.eclipse.search/icons/full/clcl16/search_rem.gif
org.eclipse.search/icons/full/clcl16/search_remall.gif
org.eclipse.search/icons/full/clcl16/search_sortmatch.gif
org.eclipse.search/icons/full/clcl16/search_stop.gif
org.eclipse.search/icons/full/ctool16/search.gif
org.eclipse.search/icons/full/cview16/searchres.gif
org.eclipse.search/icons/full/dlcl16/search_goto.gif
org.eclipse.search/icons/full/dlcl16/search_history.gif
org.eclipse.search/icons/full/dlcl16/search_next.gif
org.eclipse.search/icons/full/dlcl16/search_prev.gif
org.eclipse.search/icons/full/dlcl16/search_rem.gif
org.eclipse.search/icons/full/dlcl16/search_remall.gif
org.eclipse.search/icons/full/dlcl16/search_sortmatch.gif
org.eclipse.search/icons/full/dlcl16/search_stop.gif
org.eclipse.search/icons/full/dtool16/search.gif
org.eclipse.search/icons/full/elcl16/search_goto.gif
org.eclipse.search/icons/full/elcl16/search_history.gif
org.eclipse.search/icons/full/elcl16/search_next.gif
org.eclipse.search/icons/full/elcl16/search_prev.gif
org.eclipse.search/icons/full/elcl16/search_rem.gif
org.eclipse.search/icons/full/elcl16/search_remall.gif
org.eclipse.search/icons/full/elcl16/search_sortmatch.gif
org.eclipse.search/icons/full/elcl16/search_stop.gif
org.eclipse.search/icons/full/etool16/search.gif
org.eclipse.search/icons/full/eview16/searchres.gif
org.eclipse.search/icons/full/obj16/searchm_obj.gif
org.eclipse.search/icons/full/obj16/tsearch_dpdn_obj.gif
org.eclipse.search/icons/full/obj16/tsearch_obj.gif
org.eclipse.search/old_buildnotes_search_2_0.html
org.eclipse.search/plugin.properties
org.eclipse.search/plugin.xml
org.eclipse.search/scripts/exportplugin.xml
org.eclipse.search/search/org/eclipse/search/internal/core/ISearchScope.java
org.eclipse.search/search/org/eclipse/search/internal/core/SearchScope.java
org.eclipse.search/search/org/eclipse/search/internal/core/text/AmountOfWorkCalculator.java
org.eclipse.search/search/org/eclipse/search/internal/core/text/ITextSearchResultCollector.java
org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngine.java
org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchScope.java
org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java
org.eclipse.search/search/org/eclipse/search/internal/core/text/TypedResourceVisitor.java
org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/GotoMarkerAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ISearchHelpContextIds.java
org.eclipse.search/search/org/eclipse/search/internal/ui/OpenFileSearchPageAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllResultsAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllSearchesAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveMatchAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java
org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchAgainAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultContentProvider.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ShowNextResultAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ShowPreviousResultAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/SorterDescriptor.java
org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/GotoMarkerAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/GroupByKeyComputer.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcePathSorter.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcenameSorter.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchActionGroup.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchOperation.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java
org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExceptionHandler.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListDialog.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/MessageLine.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/RowLayouter.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/SWTUtil.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/StringMatcher.java
org.eclipse.search/search/org/eclipse/search/internal/ui/util/TypeFilteringDialog.java
org.eclipse.search/search/org/eclipse/search/ui/IActionGroupFactory.java
org.eclipse.search/search/org/eclipse/search/ui/IContextMenuConstants.java
org.eclipse.search/search/org/eclipse/search/ui/IContextMenuContributor.java
org.eclipse.search/search/org/eclipse/search/ui/IGroupByKeyComputer.java
org.eclipse.search/search/org/eclipse/search/ui/ISearchPage.java
org.eclipse.search/search/org/eclipse/search/ui/ISearchPageContainer.java
org.eclipse.search/search/org/eclipse/search/ui/ISearchPageScoreComputer.java
org.eclipse.search/search/org/eclipse/search/ui/ISearchResultView.java
org.eclipse.search/search/org/eclipse/search/ui/ISearchResultViewEntry.java
org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java
org.eclipse.search/search/org/eclipse/search/ui/package.html
org.eclipse.text/.classpath
org.eclipse.text/.cvsignore
org.eclipse.text/.project
org.eclipse.text/build.properties
org.eclipse.text/plugin.properties
org.eclipse.text/plugin.xml
org.eclipse.text/scripts/exportplugin.xml
org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java
org.eclipse.text/src/org/eclipse/jface/text/Assert.java
org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java
org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java
org.eclipse.text/src/org/eclipse/jface/text/ChildDocument.java
org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentEvent.java
org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java
org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java
org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java
org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java
org.eclipse.text/src/org/eclipse/jface/text/Document.java
org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java
org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java
org.eclipse.text/src/org/eclipse/jface/text/IDocument.java
org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java
org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java
org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java
org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java
org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java
org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java
org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java
org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java
org.eclipse.text/src/org/eclipse/jface/text/IRegion.java
org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java
org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java
org.eclipse.text/src/org/eclipse/jface/text/Line.java
org.eclipse.text/src/org/eclipse/jface/text/Position.java
org.eclipse.text/src/org/eclipse/jface/text/Region.java
org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java
org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java
org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java
org.eclipse.ui.examples.javaeditor/.classpath
org.eclipse.ui.examples.javaeditor/.cvsignore
org.eclipse.ui.examples.javaeditor/.project
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java
org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java
org.eclipse.ui.examples.javaeditor/about.html
org.eclipse.ui.examples.javaeditor/build.properties
org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm
org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm
org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif
org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gif
org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html
org.eclipse.ui.examples.javaeditor/icons/obj16/java.gif
org.eclipse.ui.examples.javaeditor/plugin.properties
org.eclipse.ui.examples.javaeditor/plugin.xml
org.eclipse.ui.workbench.texteditor/.classpath
org.eclipse.ui.workbench.texteditor/.cvsignore
org.eclipse.ui.workbench.texteditor/.project
org.eclipse.ui.workbench.texteditor/build.properties
org.eclipse.ui.workbench.texteditor/plugin.properties
org.eclipse.ui.workbench.texteditor/plugin.xml
org.eclipse.ui.workbench.texteditor/scripts/exportplugin.xml
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractDocumentProvider.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractMarkerAnnotationModel.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractRulerActionDelegate.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AddMarkerAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicMarkerUpdater.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BookmarkRulerAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ContentAssistAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConvertLineDelimitersAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultRangeIndicator.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineTarget.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.properties
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorStatusLine.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/GotoLineAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProvider.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProviderExtension.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IEditorStatusLine.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListener.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListenerExtension.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IMarkerUpdater.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IReadOnlyDependent.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IStatusField.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditor.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorExtension.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IUpdate.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IWorkbenchActionDefinitionIds.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindTarget.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/InfoForm.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkRegionTarget.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerAnnotation.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerInfoAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUpdater.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUtilities.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/PropagatingFontFieldEditor.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceMarkerAnnotationModel.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RetargetTextEditorAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RevertToSavedAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SaveAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ShiftAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusLineContributionItem.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusTextEditor.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextEditorAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextNavigationAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextOperationAction.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextSelectionNavigationLocation.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextUtilities.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WorkbenchChainedTextFontFieldEditor.java
org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/package.html
412 files changed, 0 insertions, 59473 deletions
diff --git a/org.eclipse.jface.text/.classpath b/org.eclipse.jface.text/.classpath deleted file mode 100644 index a72fd369dca..00000000000 --- a/org.eclipse.jface.text/.classpath +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="/org.eclipse.text"/> - <classpathentry kind="src" path="/org.eclipse.jface"/> - <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> - <classpathentry kind="src" path="/org.eclipse.core.runtime"/> - <classpathentry kind="src" path="/org.eclipse.swt"/> - <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/.project b/org.eclipse.jface.text/.project deleted file mode 100644 index 85dd8245086..00000000000 --- a/org.eclipse.jface.text/.project +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jface.text</name> - <comment></comment> - <projects> - <project>org.eclipse.core.runtime</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> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/org.eclipse.jface.text/build.properties b/org.eclipse.jface.text/build.properties deleted file mode 100644 index d435043c207..00000000000 --- a/org.eclipse.jface.text/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -bin.includes = plugin.properties,\ - plugin.xml,\ - *.jar -source.jfacetext.jar = src/ diff --git a/org.eclipse.jface.text/plugin.properties b/org.eclipse.jface.text/plugin.properties deleted file mode 100644 index 2efc0cbc039..00000000000 --- a/org.eclipse.jface.text/plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -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 6bd501768a3..00000000000 --- a/org.eclipse.jface.text/plugin.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<plugin - id="org.eclipse.jface.text" - name="%pluginName" - version="2.1.0" - provider-name="%providerName"> - - <runtime> - <library name="jfacetext.jar"> - <export name="*"/> - </library> - </runtime> - - <requires> - <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/scripts/exportplugin.xml b/org.eclipse.jface.text/scripts/exportplugin.xml deleted file mode 100644 index 3831f586340..00000000000 --- a/org.eclipse.jface.text/scripts/exportplugin.xml +++ /dev/null @@ -1,28 +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="_2.1.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" /> - </zip> - </target> -</project> 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 0f006c35295..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractHoverInformationControlManager.java +++ /dev/null @@ -1,463 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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; - -import org.eclipse.jface.util.Assert; - - -/** - * 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, 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 closer's information control */ - private IInformationControl fInformationControl; - /** 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) { - fInformationControl= control; - } - - /* - * @see IInformationControlCloser#start(Rectangle) - */ - public void start(Rectangle subjectArea) { - - if (fIsActive) - return; - fIsActive= true; - - fSubjectArea= subjectArea; - - setEnabled(false); - - 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 MouseMoveListener#mouseMove - */ - public void mouseMove(MouseEvent event) { - if (!fSubjectArea.contains(event.x, event.y)) - stop(); - } - - /* - * @see MouseListener#mouseUp(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 { - - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18393 - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19686 - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19719 - - /** 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 computing the start function. */ - private boolean fIsActive= false; - /** Indicates whether the mouse has been lost. */ - private boolean fMouseLost= false; - /** Indicates whether the subject control's shelll has been deactivated. */ - private boolean fShellDeactivated= false; - - /** - * Creates a new mouse tracker. - */ - public MouseTracker() { - } - - /** - * Sets this mouse tracker's subject area, the area to be tracked in order - * to reenable 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); - - fIsActive= false; - fMouseLost= false; - fShellDeactivated= 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); - } - - fMouseLost= false; - fShellDeactivated= false; - } - - /** - * 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. - */ - public void mouseHover(MouseEvent event) { - - if (fIsActive) - return; - - fIsActive= true; - fMouseLost= false; - fShellDeactivated= false; - - setEnabled(false); - - fHoverEventLocation= new Point(event.x, event.y); - 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 (fIsActive) - return; - - if (fSubjectControl != null && !fSubjectControl.isDisposed()) { - fSubjectControl.removeMouseMoveListener(this); - fSubjectControl.getShell().removeShellListener(this); - } - - setEnabled(true); - } - - /* - * @see MouseTrackListener#mouseEnter(MouseEvent) - */ - public void mouseEnter(MouseEvent e) { - } - - /* - * @see MouseTrackListener#mouseExit(MouseEvent) - */ - public void mouseExit(MouseEvent e) { - fMouseLost= 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) { - fShellDeactivated= true; - deactivate(); - } - - /* - * @see ShellListener#shellIconified(ShellEvent) - */ - public void shellIconified(ShellEvent e) { - fShellDeactivated= true; - deactivate(); - } - - /** - * Tells this tracker that the start function processing has been completed. - */ - public void computationCompleted() { - fIsActive= false; - fMouseLost= false; - fShellDeactivated= false; - } - - /** - * Determines whether the computed information is still useful for presentation. - * This is 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 (fMouseLost || fShellDeactivated) - 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 location */ - private Point fHoverEventLocation= new Point(-1, -1); - - /** - * 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() { - - 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) { - if (is) - fMouseTracker.start(getSubjectControl()); - else - fMouseTracker.stop(); - } - } - - /** - * 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 fHoverEventLocation; - } -}
\ No newline at end of file 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 d9d8c54b85d..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractInformationControlManager.java +++ /dev/null @@ -1,680 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.jface.util.Assert; - - -/** - * 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. - * - * @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(); - }; - - - - /** - * Constitues 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]; - - - - /** 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 String fInformation; - - /** Indicates whether the information control takes focus when visible */ - private boolean fTakesFocusWhenVisible= false; - - /** The information control */ - private IInformationControl fInformationControl; - - /** The information control creator */ - private IInformationControlCreator fInformationControlCreator; - - /** The information control closer */ - private IInformationControlCloser fInformationControlCloser; - - /** Indicates that the information control has been disposed */ - private 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; - - - /** - * 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 } - * <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 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; - } - - /** - * 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; - } - - /** - * 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); - } - - /** - * 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; - } - - /** - * Handles the disposal of the information control. By default, the information - * control closer is stopped. - */ - protected void handleInformationControlDisposed() { - 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 (fInformationControl == null && !fDisposed) { - - fInformationControl= fInformationControlCreator.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 - */ - protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) { - - 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 alying 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 true; - - } 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 true; - } - - 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() { - if (fSubjectArea != null && fInformation != null && fInformation.trim().length() > 0) - 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, String information) { - - IInformationControl hoverControl= getInformationControl(); - if (hoverControl != null) { - - Point sizeConstraints= computeSizeConstraints(fSubjectControl, hoverControl); - hoverControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y); - hoverControl.setInformation(information); - - if (hoverControl instanceof IInformationControlExtension) { - IInformationControlExtension extension= (IInformationControlExtension) hoverControl; - if (!extension.hasContents()) - return; - } - - Point size= hoverControl.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; - } - - hoverControl.setSize(size.x, size.y); - - Point location= computeInformationControlLocation(subjectArea, size); - hoverControl.setLocation(location); - - showInformationControl(subjectArea); - } - } - - /** - * Hides the information control and stops the information control closer. - */ - protected void hideInformationControl() { - if (fInformationControl != null) { - 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(); - - fInformationControlCreator= null; - fInformationControlCloser= null; - } - } -}
\ No newline at end of file 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 7b63ae3d602..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultAutoIndentStrategy.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -/** - * 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); - } -}
\ No newline at end of file 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 e1d2294fb7e..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.java +++ /dev/null @@ -1,284 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -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.Point; -import org.eclipse.swt.widgets.Display; -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 { - - /** - * 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; - /** Right margin in pixels. */ - private static final int RIGHT_MARGIN= 3; - - /** 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; - - - - /** - * 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 presenter the presenter to be used - * @param style the additional styles for the styled text widget - */ - public DefaultInformationControl(Shell parent, int style, IInformationPresenter presenter) { - - fShell= new Shell(parent, SWT.NO_FOCUS | SWT.NO_TRIM | SWT.ON_TOP); - fText= new StyledText(fShell, SWT.MULTI | SWT.READ_ONLY | style); - - Display display= fShell.getDisplay(); - - fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); - - 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; - } - - /** - * 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) { - if (!fShell.isDisposed()) - fShell.dispose(); - fShell= null; - fText= null; - } - } - - /* - * @see IInformationControl#setSize(int, int) - */ - public void setSize(int width, int height) { - fShell.setSize(width, height); - - width -= BORDER * 2; - if (width < 0) - width= 0; - - height -= BORDER * 2; - if (height < 0) - height= 0; - - fText.setSize(width, height); - } - - /* - * @see IInformationControl#setLocation(Point) - */ - public void setLocation(Point location) { - fText.setLocation(BORDER, BORDER); - 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 point= fText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); - point.x += RIGHT_MARGIN + BORDER * 2; - point.y += BORDER * 2; - - return point; - } - - /* - * @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() { - 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 a8934267a33..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java +++ /dev/null @@ -1,218 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 58ca1ea89ba..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultUndoManager.java +++ /dev/null @@ -1,786 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 listeners 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 ITextViewer - * @see ITextListener - * @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. - * - * @param text the text widget to be modified - * @since 2.0 - */ - protected void undoTextChange(StyledText text) { - text.replaceTextRange(fStart, fText.length(), fPreservedText); - } - - /** - * Undo the change described by this command. Also selects and - * reveals the change. - * - * @param text the text widget to be modified - */ - protected void undo(StyledText text) { - - undoTextChange(text); - - int length= fPreservedText == null ? 0 : fPreservedText.length(); - IRegion visible= fTextViewer.getVisibleRegion(); - int offset= fStart + visible.getOffset(); - fTextViewer.setSelectedRange(offset, length); - fTextViewer.revealRange(offset, length); - } - - /** - * Redo the change described by this command. - * - * @param text the text widget to be modified - * @since 2.0 - */ - protected void redoTextChange(StyledText text) { - text.replaceTextRange(fStart, fEnd - fStart, fText); - } - - /** - * Redo the change described by this command that previously been - * rolled back. Also selects and reveals the change. - * - * @param text the text widget to be modified - */ - protected void redo(StyledText text) { - - redoTextChange(text); - - int length= fText == null ? 0 : fText.length(); - IRegion visible= fTextViewer.getVisibleRegion(); - int offset= fStart + visible.getOffset(); - fTextViewer.setSelectedRange(offset, length); - fTextViewer.revealRange(offset, 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 TextCommand#undo - */ - protected void undo(StyledText text) { - 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(text); - } - - c= (TextCommand) fCommands.get(0); - c.undo(text); - } - - } finally { - if (extension != null) - extension.setRedraw(true); - } - } - - /* - * @see TextCommand#redo - */ - protected void redo(StyledText text) { - - 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(text); - } - - c= (TextCommand) fCommands.get(size -1); - c.redo(text); - } - - } 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; - } - }; - - /** - * Represents pretended <code>UndoManager</code> state. - */ - class PretendedUndoManagerState { - protected int cmdCounter= -1; - 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 text changes. - */ - class TextListener implements ITextListener { - - /* - * @see ITextListener#textChanged - */ - public void textChanged(TextEvent e) { - if (e.getDocumentEvent() != null) - processTextEvent(e); - } - }; - - /** 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 text listener */ - private ITextListener fTextListener; - /** The internal key and mouse event listener */ - private KeyAndMouseListener fKeyAndMouseListener; - - - /** Indicates inserting state */ - private boolean fInserting= false; - /** Indicates deleteing state */ - private boolean fDeleting= 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); - listenToTextChanges(true); - } - } - - /** - * Deregister all previously installed listeners from the text viewer. - */ - private void removeListeners() { - StyledText text= fTextViewer.getTextWidget(); - if (text != null && fKeyAndMouseListener != null) { - text.removeMouseListener(fKeyAndMouseListener); - text.removeKeyListener(fKeyAndMouseListener); - 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 && fTextListener == null) { - fTextListener= new TextListener(); - fTextViewer.addTextListener(fTextListener); - } else if (!listen && fTextListener != null) { - fTextViewer.removeTextListener(fTextListener); - fTextListener= null; - } - } - - /** - * Closes the current editing command and opens a new one. - */ - private void commit() { - - fInserting= false; - fDeleting= false; - fOverwriting= false; - fPreviousDelete.reinitialize(); - - fCurrent.commit(); - } - - /** - * Does redo the previously undone editing command. - */ - private void internalRedo() { - StyledText text= fTextViewer.getTextWidget(); - if (text != null) { - - ++fCommandCounter; - TextCommand cmd= (TextCommand) fCommandStack.get(fCommandCounter); - - listenToTextChanges(false); - cmd.redo(text); - listenToTextChanges(true); - - fCurrent= new TextCommand(); - } - } - - /** - * Does undo the last editing command. - */ - private void internalUndo() { - StyledText text= fTextViewer.getTextWidget(); - if (text != null) { - - TextCommand cmd= (TextCommand) fCommandStack.get(fCommandCounter); - -- fCommandCounter; - - listenToTextChanges(false); - cmd.undo(text); - 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; - } - - /** - * 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; - } - - /** - * Processes the given text event in order to determine editor command. - * - * @param e the text event - */ - private void processTextEvent(TextEvent e) { - - int start= e.getOffset(); - int end= e.getOffset() + e.getLength(); - String newText= e.getText(); - String oldText= e.getReplacedText(); - - - if (newText == null) - newText= ""; //$NON-NLS-1$ - - if (oldText == null) - oldText= ""; //$NON-NLS-1$ - - int length= newText.length(); - int diff= end - start; - - // normalize verify command - if (diff < 0) { - int tmp= end; - end= start; - start= tmp; - diff= -diff; - } - - if (start == end) { - // text will be inserted - if ((length == 1) || isWhitespaceText(newText)) { - // by typing or model manipulation - if (!fInserting || (start != fCurrent.fStart + fTextBuffer.length())) { - commit(); - fInserting= true; - } - if (fCurrent.fStart < 0) - fCurrent.fStart= fCurrent.fEnd= start; - if (length > 0) - fTextBuffer.append(newText); - } else if (length > 0) { - // by pasting - commit(); - fCurrent.fStart= fCurrent.fEnd= start; - fTextBuffer.append(newText); - } - } else { - if (length == 0) { - // text will be deleted by backspace or DEL key or empty clipboard - length= oldText.length(); - String[] delimiters= fTextViewer.getDocument().getLegalLineDelimiters(); - - if ((length == 1) || TextUtilities.equals(delimiters, oldText) > -1) { - - // whereby selection is empty - - if (fPreviousDelete.fStart == start && fPreviousDelete.fEnd == end) { - // repeated DEL - - // correct wrong settings of fCurrent - if (fCurrent.fStart == end && fCurrent.fEnd == start) { - fCurrent.fStart= start; - fCurrent.fEnd= end; - } - // append to buffer && extend command range - fPreservedTextBuffer.append(oldText); - ++fCurrent.fEnd; - - } else if (fPreviousDelete.fStart == end) { - // repeated backspace - - // insert in buffer and extend command range - fPreservedTextBuffer.insert(0, oldText); - fCurrent.fStart= start; - - } else { - // either DEL or backspace for the first time - - commit(); - fDeleting= true; - - // as we can not decide whether it was DEL or backspace we initialize for backspace - fPreservedTextBuffer.append(oldText); - fCurrent.fStart= start; - fCurrent.fEnd= end; - } - - fPreviousDelete.set(start, end); - - } else if (length > 0) { - // whereby selection is not empty - commit(); - fCurrent.fStart= start; - fCurrent.fEnd= end; - fPreservedTextBuffer.append(oldText); - } - } else { - // text will be replaced - - if (length == 1) { - length= oldText.length(); - String[] delimiters= fTextViewer.getDocument().getLegalLineDelimiters(); - - if ((length == 1) || TextUtilities.equals(delimiters, oldText) > -1) { - // because of overwrite mode or model manipulation - if (!fOverwriting || (start != fCurrent.fStart + fTextBuffer.length())) { - commit(); - fOverwriting= true; - } - - if (fCurrent.fStart < 0) - fCurrent.fStart= start; - - fCurrent.fEnd= end; - fTextBuffer.append(newText); - fPreservedTextBuffer.append(oldText); - return; - } - } - // because of typing or pasting whereby selection is not empty - commit(); - fCurrent.fStart= start; - fCurrent.fEnd= end; - fTextBuffer.append(newText); - fPreservedTextBuffer.append(oldText); - } - } - } - - /* - * @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; - fDeleting= 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()) { - commit(); - internalUndo(); - } - } -} diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentAdapter.java deleted file mode 100644 index 8ca9b21ebcc..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentAdapter.java +++ /dev/null @@ -1,338 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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;
import org.eclipse.jface.util.Assert; - - -/** - * Adapts an <code>IDocument</code> to the <code>StyledTextContent</code> interface. - */ -class DocumentAdapter implements IDocumentAdapter, IDocumentListener, IDocumentAdapterExtension { - - /** The adapted document. */ - private IDocument fDocument; - /** 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; - /** - * Indicates whether the current document event describes a complete replace. - * @since 2.0 - */ - private boolean fDocumentContentReplaced= false; - /** - * Indicates that the line delimiter cache is flushed - * @since 2.0 - */ - private boolean fInvalidateLineDelimiter; - - - /** - * Creates a new document adapter which is initiallly not connected to - * any document. - */ - public DocumentAdapter() { - } - - /** - * 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 (fDocument != null) - fDocument.addPrenotifiedDocumentListener(this); - } - - /* - * @see StyledTextContent#addTextChangeListener - */ - public void addTextChangeListener(TextChangeListener listener) { - Assert.isNotNull(listener); - if (! fTextChangeListeners.contains(listener)) - fTextChangeListeners.add(listener); - } - - /* - * @see StyledTextContent#removeTextChangeListener - */ - public void removeTextChangeListener(TextChangeListener listener) { - Assert.isNotNull(listener); - fTextChangeListeners.remove(listener); - } - - /* - * @see StyledTextContent#getLine(int) - */ - public String getLine(int line) { - try { - IRegion r= fDocument.getLineInformation(line); - return fDocument.get(r.getOffset(), r.getLength()); - } catch (BadLocationException x) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return null; - } - } - - /* - * @see StyledTextContent#getLineAtOffset(int) - */ - public int getLineAtOffset(int offset) { - try { - return fDocument.getLineOfOffset(offset); - } catch (BadLocationException x) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return -1; - } - } - - /* - * @see StyledTextContent#getLineCount() - */ - public int getLineCount() { - return fDocument.getNumberOfLines(); - } - - /* - * @see StyledTextContent#getOffsetAtLine(int) - */ - public int getOffsetAtLine(int line) { - try { - return fDocument.getLineOffset(line); - } catch (BadLocationException x) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return -1; - } - } - - /* - * @see StyledTextContent#getTextRange(int, int) - */ - public String getTextRange(int offset, int length) { - try { - return fDocument.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 - */ - public void setText(String text) { - fDocument.set(text); - } - - /* - * @see StyledTextContent#getCharCount() - */ - public int getCharCount() { - return fDocument.getLength(); - } - - /* - * @see StyledTextContent#getLineDelimiter - */ - public String getLineDelimiter() { - - if (fLineDelimiter == null) { - - try { - fLineDelimiter= fDocument.getLineDelimiter(0); - } catch (BadLocationException x) { - } - - if (fLineDelimiter == null) { - /* - * Follow up fix for: 1GF5UU0: ITPJUI:WIN2000 - "Organize Imports" in java editor inserts lines in wrong format - * The line delimiter must always be a legal document line delimiter. - */ - String sysLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ - String[] delimiters= fDocument.getLegalLineDelimiters(); - Assert.isTrue(delimiters.length > 0); - for (int i= 0; i < delimiters.length; i++) { - if (delimiters[i].equals(sysLineDelimiter)) { - fLineDelimiter= sysLineDelimiter; - break; - } - } - - if (fLineDelimiter == null) { - // system line delimiter is not a legal document line delimiter - fLineDelimiter= delimiters[0]; - } - } - } - - 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) { - - // http://dev.eclipse.org/bugs/show_bug.cgi?id=15159 - if (fDocumentContentReplaced) { - fDocumentContentReplaced= false; - fireTextSet(); - } else - fireTextChanged(); - - if (fInvalidateLineDelimiter) { - fLineDelimiter= null; - fInvalidateLineDelimiter= false; - } - } - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - - if (event.getOffset() == 0 && event.getLength() == fDocument.getLength()) { - // http://dev.eclipse.org/bugs/show_bug.cgi?id=15159 - fEvent= event; - fInvalidateLineDelimiter= true; - fDocumentContentReplaced= true; - - } else { - - try { - // invalidate cached line delimiter if first line of document was changed - if (event.getOffset() < fDocument.getLineLength(0)) - fInvalidateLineDelimiter= true; - } catch (BadLocationException e) { - } - - // Remember the given event - fEvent= event; - fireTextChanging(); - } - } - - /** - * 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; - fireTextSet(); - } - - /* - * @see IDocumentAdapterExtension#stopForwardingDocumentChanges() - * @since 2.0 - */ - public void stopForwardingDocumentChanges() { - fIsForwarding= false; - } -}
\ No newline at end of file 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 a79245254a6..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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>. - */ -public final class DocumentCommand { - - /** 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; - - - /** - * Creates a new document command. - */ - DocumentCommand() { - } - - /** - * Translates a verify event into a document replace command using the given offset. - * - * @param event the event to be translated - * @param offset the offset used for the translation - */ - void setEvent(VerifyEvent event, int offset) { - - doit= true; - - text= event.text; - - this.offset= event.start; - length= event.end - event.start; - - if (length < 0) { - this.offset += length; - length= -length; - } - - this.offset += offset; - } - - /** - * 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 offset to be considered for range comparison - * @return <code>true</code> if this command and the event cover the same range - */ - boolean fillEvent(VerifyEvent event, int offset) { - - int start= this.offset - offset; - - event.text= text; - event.doit= (start == event.start && start + length == event.end) && doit; - return event.doit; - } -} - - 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 c0e48790d5d..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoIndentStrategy.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * An auto indent 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 or - * use the standard implementation <code>DefaultAutoIndentStrategy</code>. - */ -public interface IAutoIndentStrategy { - - /** - * Allows the strategy to manipulate the document command. - * - * @param document the document that will be changed - * @param command the document command describing the indented change - */ - void customizeDocumentCommand(IDocument document, DocumentCommand command); -}
\ No newline at end of file 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 49c6c6a6f7b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapter.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 d44d18e6afd..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapterExtension.java +++ /dev/null @@ -1,39 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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>stopTranslatingDocumentChanges</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 700704992ea..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IEventConsumer.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.swt.events.VerifyEvent; - -/** - * Implementers can register with an 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. - * - * @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 65836936737..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTarget.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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(); - - /** - * Finds and selects a string starting at the given offset using the specified search - * directives. - * - * @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 - * @return the position of the specified string, or -1 if the string has not been found - */ - int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord); - - /** - * Returns the currently selected range of characters as a offset and length. - * - * @return the currently selected character range - */ - 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 2cc904da748..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension.java +++ /dev/null @@ -1,89 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 the state of 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/IInformationControl.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java deleted file mode 100644 index 5a4518517fa..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java +++ /dev/null @@ -1,142 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 either be 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 in 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 is called before - * <code>computeSizeHint</code> is called. - * - * @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 - * returns 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 affect. - * - * @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); -}
\ No newline at end of file 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 be08cefd1ce..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreator.java +++ /dev/null @@ -1,33 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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/IInformationControlExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java deleted file mode 100644 index 077ee59d096..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java +++ /dev/null @@ -1,29 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 infomation 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(); -}
\ No newline at end of file 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 f65f08f26f0..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkRegionTarget.java +++ /dev/null @@ -1,32 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 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 91341a8b581..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkSelection.java +++ /dev/null @@ -1,48 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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/IRewriteTarget.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java deleted file mode 100644 index 559108d91d2..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java +++ /dev/null @@ -1,55 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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/ITextDoubleClickStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java deleted file mode 100644 index c77c7dc720b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * 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 ITextViewer - * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(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 727903192d3..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHover.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * 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 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); -}
\ No newline at end of file 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 016b9ace037..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextInputListener.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * 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 ITextViewer - * @see 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); -}
\ No newline at end of file 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 ba600611136..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextListener.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Text listeners registered with an 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 according 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 ITextViewer - * @see TextEvent - * @see 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 9ae0600c15b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTarget.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * 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 e96e370e8c9..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTargetExtension.java +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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. - * - * @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/ITextSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java deleted file mode 100644 index 7967c4d5294..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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>. - */ -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 4cf7376eb87..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewer.java +++ /dev/null @@ -1,432 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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> viewport listeners to inform about changes of the viewer's viewport - * <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(); - - - /* --------- plugins --------- */ - - /** - * 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 viewport 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 viewport 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 approriate <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 mode. - * - * @param editable the editable mode - */ - void setEditable(boolean editable); - - /** - * Returns whether the shown text can be manipulated. - * - * @return the viewer's editable mode - */ - boolean isEditable(); - - - /* ----------- visible region support ------------- */ - - /** - * Sets the given document as this viewer's model and - * makes the specified region visible in the presentation. An approriate - * <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 visibleRegionOffset the offset of the visible region - * @param visibleRegionLength the length of the visible region - */ - void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength); - - /** - * 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. - * - * @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 viewport. - * - * @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 viewport. 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(); -}
\ No newline at end of file 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 ccc6f1314e9..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension.java +++ /dev/null @@ -1,101 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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. - */ - 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/IUndoManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java deleted file mode 100644 index 1a372371d16..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * 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>. - */ -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(); - -}
\ No newline at end of file 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 8677db81254..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IViewportListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * 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 ITextViewer - */ -public interface IViewportListener { - - /** - * Informs about viewport changes. The given vertical position - * is the new vertical scrolling offset measured in pixels. - */ - 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 a11f3668dec..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeper.java +++ /dev/null @@ -1,34 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 back 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/IWidgetTokenOwner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java deleted file mode 100644 index 6c82bc7fbc3..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java +++ /dev/null @@ -1,45 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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/JFaceTextMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java deleted file mode 100644 index 62940e97f04..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -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 295194358a6..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.properties +++ /dev/null @@ -1,28 +0,0 @@ -######################################### -# (c) Copyright IBM Corp. 2000, 2001. -# All Rights Reserved. -######################################### - - -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 - -InfoPopup.info_delay_timer_name=AdditionalInfo Delay - -ContentAssistant.assist_delay_timer_name=AutoAssist Delay - -AbstractHoverInformationControlManager.hover.restarter=Hover Restart Delay 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 83cb0b5e11a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/MarkSelection.java +++ /dev/null @@ -1,69 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v0.5 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v05.html - -Contributors: - IBM Corporation - Initial 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/PropagatingFontFieldEditor.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java deleted file mode 100644 index e3191672423..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java +++ /dev/null @@ -1,132 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 - */ -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 1a1e1fff94b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextAttribute.java +++ /dev/null @@ -1,121 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 - */ - 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; - } -}
\ No newline at end of file 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 22c1d30099f..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextEvent.java +++ /dev/null @@ -1,119 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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. - * Client's 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 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; - } -}
\ No newline at end of file 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 1c20dbb68cb..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java +++ /dev/null @@ -1,398 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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, consequtive 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 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 { - - protected int fIndex; - protected int fLength; - protected boolean fSkipDefaults; - 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. - */ - 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. - * - * @return <code>true</code> if teh 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 syle information for the range covered by the whole presentation */ - private StyleRange fDefaultRange; - /** The member ranges of the presentation */ - private ArrayList fRanges= new ArrayList(); - /** A clipping region against which the presentation can be clipped when asked for results */ - private IRegion fResultWindow; - - - /** - * Creates a new empty text presentation. - */ - public TextPresentation() { - } - - /** - * 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 decribing 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() { - return createWindowRelativeRange(fResultWindow, fDefaultRange); - } - - /** - * 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); - } - - /** - * 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 -= (defaultEnd - end); - } - } - - /** - * 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) { - int i= 0; - if (window != null) { - int start= window.getOffset(); - while (i < fRanges.size()) { - StyleRange r= (StyleRange) fRanges.get(i++); - if (r.start + r.length > start) { - -- i; - break; - } - } - } - return i; - } - - /** - * 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) { - int i= fRanges.size(); - if (window != null) { - int end= window.getOffset() + window.getLength(); - while (i > 0) { - StyleRange r= (StyleRange) fRanges.get(--i); - if (r.start < end) { - ++ i; - break; - } - } - } - return i; - } - - /** - * 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 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 interator - */ - 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 smalled 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); - } - - /** - * Clears this presentation by resetting all applied changes. - * @since 2.0 - */ - public void clear() { - fDefaultRange= null; - fResultWindow= null; - fRanges.clear(); - } -}
\ No newline at end of file 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 a4b60a41e1e..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java +++ /dev/null @@ -1,175 +0,0 @@ -package org.eclipse.jface.text; - - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Standard implementation of <code>ITextSelection</code>. - * Makes atvantage 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 { - - private final static ITextSelection NULL= new TextSelection(); - - /** - * Returns 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. - */ - /* - * @see 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) - return fDocument.getLineOfOffset(fOffset + fLength - 1); - } 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 6563014adc6..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java +++ /dev/null @@ -1,3432 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -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.custom.LineBackgroundEvent; -import org.eclipse.swt.custom.LineBackgroundListener; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.custom.ST; -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.MouseMoveListener; -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.ScrollBar; - -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.Viewer; - - - -/** - * 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 no 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, - ITextOperationTarget, ITextOperationTargetExtension, - IWidgetTokenOwner { - - /** 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 { - - public DocumentEvent event; - public int start, length; - 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 { - 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, MouseMoveListener, 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.removeMouseMoveListener(this); - updateViewportListeners(MOUSE_END); - } - - /* - * @see MouseListener#mouseDown - */ - public void mouseDown(MouseEvent e) { - if (fTextWidget != null) - fTextWidget.addMouseMoveListener(this); - } - - /* - * @see MouseMoveListener#mouseMove - */ - public void mouseMove(MouseEvent e) { - updateViewportListeners(MOUSE); - } - - /* - * @see SelectionListener#widgetSelected - */ - public void widgetSelected(SelectionEvent e) { - updateViewportListeners(SCROLLER); - } - - /* - * @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. - */ - class DocumentListener implements IDocumentListener { - - /* - * @see IDocumentListener#documentAboutToBeChanged - */ - public void documentAboutToBeChanged(DocumentEvent e) { - if (e.getDocument() == getVisibleDocument()) - fWidgetCommand.setEvent(e); - } - - /* - * @see IDocumentListener#documentChanged - */ - public void documentChanged(final DocumentEvent e) { - if (fWidgetCommand.event == e) - updateTextListeners(fWidgetCommand); - } - }; - - - /** - * 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 reponsible for registered verify key listeners. - * Uses batches rather than robust iterators because of performance issues. - * - * @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 registed verify key listeners. */ - private List fListeners= new ArrayList(); - /** List of pending batches. */ - private List fBatched= new ArrayList(); - /** The currently active iterator. */ - private Iterator fIterator; - - /* - * @see VerifyKeyListener#verifyKey(VerifyEvent) - */ - public void verifyKey(VerifyEvent event) { - if (fListeners.isEmpty()) - return; - - fIterator= fListeners.iterator(); - while (fIterator.hasNext() && event.doit) { - VerifyKeyListener listener= (VerifyKeyListener) fIterator.next(); - listener.verifyKey(event); - } - fIterator= null; - - 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 (fIterator != null) { - - 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 (fIterator != null) { - - 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 region describing this range's extend. */ - private IRegion fRange; - /** 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= event.lineOffset + TextViewer.this.getVisibleRegionOffset(); - - 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() { - int offset= fPosition.getOffset() - TextViewer.this.getVisibleRegionOffset(); - int length= fPosition.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 { - - /** 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 IDocumentPartitioner fRememberedPartitioner; - - /* - * @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) { - Point s= TextViewer.this.getSelectedRange(); - if (s.x > -1 && s.y > -1) { - try { - IDocument document= TextViewer.this.getDocument(); - document.replace(s.x, s.y, text); - if (text != null && text.length() > 0) - TextViewer.this.setSelectedRange(s.x, text.length()); - } catch (BadLocationException x) { - } - } - } - - /* - * @see IFindReplaceTarget#isEditable() - */ - public boolean isEditable() { - return TextViewer.this.isEditable(); - } - - /* - * @see IFindReplaceTarget#getSelection() - */ - public Point getSelection() { - Point point= TextViewer.this.getSelectedRange(); - point.x -= TextViewer.this.getVisibleRegionOffset(); - return point; - } - - /* - * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean) - */ - public int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord) { - if (offset != -1) - offset += TextViewer.this.getVisibleRegionOffset(); - - if (fRange != null) { - IRegion range= fRange.getRange(); - offset= TextViewer.this.findAndSelectInRange(offset, findString, searchForward, caseSensitive, wholeWord, range.getOffset(), range.getLength()); - } else { - offset= TextViewer.this.findAndSelect(offset, findString, searchForward, caseSensitive, wholeWord); - } - - if (offset != -1) - offset -= TextViewer.this.getVisibleRegionOffset(); - - return offset; - } - - /* - * @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 - line= document.getLineOfOffset(point.x + point.y); - int length= document.getLineOffset(line) + document.getLineLength(line) - offset; - - return new Point(offset, length); - - } catch (BadLocationException e) { - // should not happen - return null; - } - } - - /* - * @see IFindReplaceTargetExtension#setSelection(int, int) - * @since 2.0 - */ - public void setSelection(int offset, int length) { - TextViewer.this.setSelectedRange(offset /*+ TextViewer.this.getVisibleRegionOffset()*/, length); - } - - /* - * @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(); - fRememberedPartitioner= document.getDocumentPartitioner(); - if (fRememberedPartitioner != null) { - fRememberedPartitioner.disconnect(); - document.setDocumentPartitioner(null); - } - - } else { - - TextViewer.this.setRedraw(true); - TextViewer.this.stopSequentialRewriteMode(); - - if (fUndoManager != null) - fUndoManager.endCompoundChange(); - - if (fRememberedPartitioner != null) { - IDocument document= TextViewer.this.getDocument(); - fRememberedPartitioner.connect(document); - document.setDocumentPartitioner(fRememberedPartitioner); - } - } - } - }; - - - /** - * 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); - } - }; - - - /** ID for originators of view port changes */ - protected static final int SCROLLER= 1; - protected static final int MOUSE= 2; - protected static final int MOUSE_END= 3; - protected static final int KEY= 4; - protected static final int RESIZE= 5; - 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 child document manager */ - private ChildDocumentManager fChildDocumentManager; - /** The text viewer's double click strategies connector */ - private TextDoubleClickStrategyConnector fDoubleClickStrategyConnector; - /** - * The text viewer's hovering controller - * @since 2.0 - */ - private AbstractHoverInformationControlManager fTextHoverManager; - /** The text viewer's viewport 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; - /** Document listener */ - private DocumentListener fDocumentListener= new DocumentListener(); - /** 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 - */ - private Position fMarkPosition; - /** - * The mark position category. - * @since 2.0 - */ - private final String MARK_POSITION_CATEGORY="__mark_category_" + hashCode(); - /** - * 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 Point fDocumentSelection; - /** - * The viewer's rewrite target - * @since 2.0 - */ - private IRewriteTarget fRewriteTarget; - - - /** 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 viewport 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; - - - //---- 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 DocumentAdapter(); - } - - /** - * 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); - } - }); - - initializeViewportUpdate(); - } - - /* - * @see Viewer#getControl - */ - public Control getControl() { - return fTextWidget; - } - - /* - * @see ITextViewer#activatePlugin - */ - public void activatePlugins() { - - if (fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty() && fDoubleClickStrategyConnector == null) { - fDoubleClickStrategyConnector= new TextDoubleClickStrategyConnector(); - fTextWidget.addMouseListener(fDoubleClickStrategyConnector); - } - - if (fTextHovers != null && !fTextHovers.isEmpty() && fHoverControlCreator != null && fTextHoverManager == null) { - fTextHoverManager= new TextViewerHoverManager(this, fHoverControlCreator); - fTextHoverManager.install(this.getTextWidget()); - } - - if (fUndoManager != null) { - fUndoManager.connect(this); - fUndoManager.reset(); - } - } - - /* - * @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() { - - removeViewPortUpdate(); - fViewportGuard= null; - - if (fViewportListeners != null) { - fViewportListeners.clear(); - fViewportListeners= null; - } - - if (fTextListeners != null) { - fTextListeners.clear(); - fTextListeners= 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 (fDocumentListener != null) - fDocumentListener= null; - - if (fVisibleDocument instanceof ChildDocument) { - ChildDocument child = (ChildDocument) fVisibleDocument; - child.removeDocumentListener(fDocumentListener); - getChildDocumentManager().freeChildDocument(child); - } - - if (fDocumentAdapter != null) { - fDocumentAdapter.setDocument(null); - fDocumentAdapter= null; - } - - fVisibleDocument= null; - fDocument= null; - fChildDocumentManager= null; - fScroller= null; - } - - - //---- simple getters and setters - - /** - * Returns viewer's text widget. - */ - public StyledText getTextWidget() { - return fTextWidget; - } - - /* - * @see ITextViewer#setAutoIndentStrategy - */ - public void setAutoIndentStrategy(IAutoIndentStrategy strategy, String contentType) { - - if (strategy != null) { - if (fAutoIndentStrategies == null) - fAutoIndentStrategies= new HashMap(); - fAutoIndentStrategies.put(contentType, strategy); - } else if (fAutoIndentStrategies != null) - fAutoIndentStrategies.remove(contentType); - } - - /* - * @see ITextViewer#setEventConsumer - */ - public void setEventConsumer(IEventConsumer consumer) { - fEventConsumer= consumer; - } - - /* - * @see ITextViewer#setIndentPrefixes - */ - 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 - */ - 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 - */ - public void setUndoManager(IUndoManager undoManager) { - fUndoManager= undoManager; - } - - /* - * @see ITextViewer#setTextHover - */ - public void setTextHover(ITextHover hover, String contentType) { - - if (hover != null) { - if (fTextHovers == null) - fTextHovers= new HashMap(); - fTextHovers.put(contentType, hover); - } else if (fTextHovers != null) - fTextHovers.remove(contentType); - } - - /** - * 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 (ITextHover) selectContentTypePlugin(offset, fTextHovers); - } - - /** - * 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 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()) - return new Point(fDocumentSelection.x, fDocumentSelection.y); - - if (fTextWidget != null) { - Point p= fTextWidget.getSelectionRange(); - int offset= getVisibleRegionOffset(); - return new Point(p.x + offset, p.y); - } - - return new Point(-1, -1); - } - - /* - * @see ITextViewer#setSelectedRange - */ - public void setSelectedRange(int offset, int length) { - - if (!redraws()) { - fDocumentSelection.x= offset; - fDocumentSelection.y= length; - return; - } - - if (fTextWidget == null) - return; - - int end= offset + length; - - IDocument document= getVisibleDocument(); - if (document == null) - return; - - if (document instanceof ChildDocument) { - Position p= ((ChildDocument) document).getParentDocumentRange(); - if (p.overlapsWith(offset, length)) { - - if (offset < p.getOffset()) - offset= p.getOffset(); - offset -= p.getOffset(); - - int e= p.getOffset() + p.getLength(); - if (end > e) - end= e; - end -= p.getOffset(); - - } else - return; - } - - length= end - offset; - - int[] selectionRange= new int[] { offset, length }; - validateSelectionRange(selectionRange); - if (selectionRange[0] >= 0 && selectionRange[1] >= 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(); - int documentLength= document.getLength(); - - int offset= selectionRange[0]; - int length= selectionRange[1]; - - - 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; - } - - 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; - } - - /** - * 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 - */ - protected void selectionChanged(int offset, int length) { - if (redraws()) { - ISelection selection= new TextSelection(getDocument(), getVisibleRegionOffset() + offset, length); - SelectionChangedEvent event= new SelectionChangedEvent(this, selection); - fireSelectionChanged(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) - offset += getVisibleRegionOffset(); - ISelection selection= new MarkSelection(getDocument(), offset, length); - SelectionChangedEvent event= new SelectionChangedEvent(this, selection); - fireSelectionChanged(event); - } - } - - - //---- Text listeners - - /* - * @see ITextViewer#addTextListener - */ - public void addTextListener(ITextListener listener) { - if (fTextListeners == null) - fTextListeners= new ArrayList(); - - if (!fTextListeners.contains(listener)) - fTextListeners.add(listener); - } - - /* - * @see ITextViewer#removeTextListener - */ - public void removeTextListener(ITextListener 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 ChildDocumentEvent) - event= ((ChildDocumentEvent) event).getParentEvent(); - - 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 - */ - public void addTextInputListener(ITextInputListener listener) { - if (fTextInputListeners == null) - fTextInputListeners= new ArrayList(); - - if (!fTextInputListeners.contains(listener)) - fTextInputListeners.add(listener); - } - - /* - * @see ITextViewer#removeTextInputListener - */ - public void removeTextInputListener(ITextInputListener 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 sucessful 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 - */ - 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); - - inputChanged(fDocument, oldDocument); - - fireInputDocumentChanged(oldDocument, fDocument); - fReplaceTextPresentation= false; - } - - /* - * @see ITextViewer#setDocument(IDocument, int int) - */ - public void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength) { - - fReplaceTextPresentation= true; - fireInputDocumentAboutToBeChanged(fDocument, document); - - IDocument oldDocument= fDocument; - fDocument= document; - - try { - int line= fDocument.getLineOfOffset(visibleRegionOffset); - int offset= fDocument.getLineOffset(line); - int length= (visibleRegionOffset - offset) + visibleRegionLength; - setVisibleDocument(getChildDocumentManager().createChildDocument(fDocument, offset, length)); - } catch (BadLocationException x) { - throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_visible_region_1")); //$NON-NLS-1$ - } - - inputChanged(fDocument, oldDocument); - - fireInputDocumentChanged(oldDocument, fDocument); - fReplaceTextPresentation= false; - } - - //---- Viewports - - /** - * Initializes all listeners and structures required to set up viewport 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 viewport 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 - */ - public void addViewportListener(IViewportListener listener) { - - if (fViewportListeners == null) { - fViewportListeners= new ArrayList(); - initializeViewportUpdate(); - } - - if (!fViewportListeners.contains(listener)) - fViewportListeners.add(listener); - } - - /* - * @see ITextViewer#removeViewportListener - */ - public void removeViewportListener(IViewportListener listener) { - if (fViewportListeners != null) - fViewportListeners.remove(listener); - } - - /** - * Checks whether the viewport 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(); - - int offset= getVisibleRegionOffset(); - if (offset > 0) { - try { - top += getDocument().getLineOfOffset(offset); - } catch (BadLocationException x) { - if (TRACE_ERRORS) - System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getTopIndex")); //$NON-NLS-1$ - return -1; - } - } - - return top; - } - - return -1; - } - - /* - * @see ITextViewer#setTopIndex - */ - public void setTopIndex(int index) { - - if (fTextWidget != null) { - - int offset= getVisibleRegionOffset(); - if (offset > 0) { - try { - index -= getDocument().getLineOfOffset(offset); - } catch (BadLocationException x) { - if (TRACE_ERRORS) - System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.setTopIndex_1")); //$NON-NLS-1$ - return; - } - } - - if (index >= 0) { - - int lines= getVisibleLinesInViewport(); - if (lines > -1 ) { - IDocument d= getVisibleDocument(); - int last= d.getNumberOfLines() - lines; - if (last > 0 && index > last) - index= last; - - fTextWidget.setTopIndex(index); - updateViewportListeners(INTERNAL); - - } else - fTextWidget.setTopIndex(index); - } - } - } - - /** - * Returns the viewport height in lines. The actual visible lines can be fewer if the - * document is shorter than the viewport. - * - * @return the viewport 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 r= getVisibleRegion(); - - try { - - IDocument d= getDocument(); - int startLine= d.getLineOfOffset(r.getOffset()); - int endLine= d.getLineOfOffset(r.getOffset() + r.getLength() - 1); - int lines= getVisibleLinesInViewport(); - - if (startLine + lines < endLine) - return getTopIndex() + lines - 1; - - 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 top + getVisibleRegionOffset(); - } 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 region= getVisibleRegion(); - int visibleRegionEndOffset= region.getOffset() + region.getLength() - 1; - return visibleRegionEndOffset < bottomEndOffset ? visibleRegionEndOffset : 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 - */ - public void revealRange(int start, int length) { - - if (fTextWidget == null || !redraws()) - return; - - int end= start + length; - - IDocument document= getVisibleDocument(); - if (document == null) - return; - - Position p= (document instanceof ChildDocument) - ? ((ChildDocument) document).getParentDocumentRange() - : new Position(0, document.getLength()); - - if (p.overlapsWith(start, length)) { - - if (start < p.getOffset()) - start= p.getOffset(); - start -= p.getOffset(); - - int e= p.getOffset() + p.getLength(); - if (end > e) - end= e; - end -= p.getOffset(); - - } else { - // http://dev.eclipse.org/bugs/show_bug.cgi?id=15159 - start= start < p.getOffset() ? 0 : p.getLength(); - end= start; - } - - internalRevealRange(start, end); - } - - /** - * 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 line= doc.getLineInformation(startLine); - startPixel= getWidthInPixels(line.getOffset(), start - line.getOffset()); - endPixel= getWidthInPixels(line.getOffset(), line.getLength()); - } else { - int lineStart= doc.getLineOffset(startLine); - startPixel= getWidthInPixels(lineStart, start - lineStart); - endPixel= getWidthInPixels(lineStart, end - lineStart); - } - - 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; - if (startPixel < visibleStart) - newOffset= startPixel; - else if (endPixel - startPixel + bufferZone < visibleEnd - visibleStart) - newOffset= visibleStart + (endPixel - visibleEnd + bufferZone); - else - newOffset= startPixel; - - fTextWidget.setHorizontalIndex(newOffset / getAverageCharWidth()); - } - - } - } catch (BadLocationException e) { - throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_range")); //$NON-NLS-1$ - } - } - - /** - * Returns the width of the text when being drawed into this viewer's widget. - * - * @param the string to messure - * @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 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 child document manager - * - * @return the child document manager - */ - private ChildDocumentManager getChildDocumentManager() { - if (fChildDocumentManager == null) - fChildDocumentManager= new ChildDocumentManager(); - return fChildDocumentManager; - } - - /** - * Invalidates the current presentation by sending an initialization - * event to all text listener. - * @since 2.0 - */ - public final void invalidateTextPresentation() { - if (fVisibleDocument != null) { - fWidgetCommand.start= 0; - fWidgetCommand.length= 0; - fWidgetCommand.text= fVisibleDocument.get(); - fWidgetCommand.event= null; - updateTextListeners(fWidgetCommand); - } - } - - /** - * 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(); - } - } - - /** - * Sets this viewer's visible document. The visible document represents the - * visible region of the viewer's input document. - * - * @param document the visible document - */ - private void setVisibleDocument(IDocument document) { - - if (fVisibleDocument != null && fDocumentListener != null) - fVisibleDocument.removeDocumentListener(fDocumentListener); - - fVisibleDocument= document; - - initializeWidgetContents(); - resetPlugins(); - - if (fVisibleDocument != null && fDocumentListener != null) - fVisibleDocument.addDocumentListener(fDocumentListener); - } - - /** - * 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#setVisibleRegion - */ - public void setVisibleRegion(int start, int length) { - - IRegion region= getVisibleRegion(); - if (start == region.getOffset() && length == region.getLength()) { - // nothing to change - return; - } - - ChildDocument child= null; - IDocument parent= getVisibleDocument(); - - if (parent instanceof ChildDocument) { - child= (ChildDocument) parent; - parent= child.getParentDocument(); - } - - try { - - int line= parent.getLineOfOffset(start); - int offset= parent.getLineOffset(line); - length += (start - offset); - - if (child != null) { - child.setParentDocumentRange(offset, length); - } else { - child= getChildDocumentManager().createChildDocument(parent, offset, length); - } - - setVisibleDocument(child); - - } catch (BadLocationException x) { - throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_visible_region_2")); //$NON-NLS-1$ - } - } - - /* - * @see ITextViewer#resetVisibleRegion - */ - public void resetVisibleRegion() { - IDocument document= getVisibleDocument(); - if (document instanceof ChildDocument) { - ChildDocument child = (ChildDocument) document; - setVisibleDocument(child.getParentDocument()); - getChildDocumentManager().freeChildDocument(child); - } - } - - /* - * @see ITextViewer#overlapsWithVisibleRegion - */ - 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#setTextDoubleClickStrategy - */ - 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 plugin - * @return the plugin registered under the offset's content type - */ - protected Object selectContentTypePlugin(int offset, Map plugins) { - try { - return selectContentTypePlugin(getDocument().getContentType(offset), 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>plugins</code> this one which is registered for - * the given content <code>type</code>. - */ - 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 <code>IAutoIndentStrategy</code>. - * - * @param command the document command representing the verify event - */ - protected void customizeDocumentCommand(DocumentCommand command) { - if (!fIgnoreAutoIndent) { - IAutoIndentStrategy s= (IAutoIndentStrategy) selectContentTypePlugin(command.offset, fAutoIndentStrategies); - if (s != null) - s.customizeDocumentCommand(getDocument(), command); - } - fIgnoreAutoIndent= false; - } - - /** - * @see VerifyListener#verifyText - */ - protected void handleVerifyEvent(VerifyEvent e) { - - if (fEventConsumer != null) { - fEventConsumer.processEvent(e); - if (!e.doit) - return; - } - - int offset= getVisibleRegionOffset(); - fDocumentCommand.setEvent(e, offset); - customizeDocumentCommand(fDocumentCommand); - if (!fDocumentCommand.fillEvent(e, offset)) { - try { - fVerifyListener.forward(false); - getDocument().replace(fDocumentCommand.offset, fDocumentCommand.length, fDocumentCommand.text); - if (fTextWidget != null) { - int caretOffset= fDocumentCommand.offset + (fDocumentCommand.text == null ? 0 : fDocumentCommand.text.length()) - offset; - fTextWidget.setCaretOffset(caretOffset); - } - } catch (BadLocationException x) { - if (TRACE_ERRORS) - System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.verifyText")); //$NON-NLS-1$ - } finally { - 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> - */ - private boolean isMarkedRegionEmpty() { - - if (fTextWidget == null) - return true; - - IRegion region= getVisibleRegion(); - int offset= region.getOffset(); - int length= region.getLength(); - - return - fMarkPosition == null || - fMarkPosition.isDeleted() || - fMarkPosition.offset < offset || - fMarkPosition.offset > offset + length; - } - - /* - * @see ITextViewer#canDoOperation - */ - 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_RIGHT: - case SHIFT_LEFT: - 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 - */ - public void doOperation(int operation) { - - if (fTextWidget == null || !redraws()) - return; - - switch (operation) { - - case UNDO: - if (fUndoManager != null) { - fIgnoreAutoIndent= true; - fUndoManager.undo(); - } - break; - case REDO: - if (fUndoManager != null) { - fIgnoreAutoIndent= true; - fUndoManager.redo(); - } - break; - case CUT: - if (fTextWidget.getSelectionCount() == 0) - copyMarkedRegion(true); - else - fTextWidget.cut(); - break; - case COPY: - if (fTextWidget.getSelectionCount() == 0) - copyMarkedRegion(false); - else - fTextWidget.copy(); - break; - case PASTE: - fIgnoreAutoIndent= true; - fTextWidget.paste(); - break; - case DELETE: - deleteText(); - break; - case SELECT_ALL: - setSelectedRange(getVisibleRegionOffset(), getVisibleDocument().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; - } - } - - /* - * @see ITextOperationTargetExtension#enableOperation(int, boolean) - * @since 2.0 - */ - public void enableOperation(int operation, boolean enable) { - /* - * No-op by default. - * Will be changed to regularily 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 - */ - private void copyMarkedRegion(boolean delete) { - - if (fTextWidget == null) - return; - - IRegion region= getVisibleRegion(); - int offset= region.getOffset(); - int length= region.getLength(); - - if (fMarkPosition == null || fMarkPosition.isDeleted() || - fMarkPosition.offset < offset || fMarkPosition.offset > offset + length) - return; - - int markOffset= fMarkPosition.offset - offset; - - Point selection= fTextWidget.getSelection(); - if (selection.x <= markOffset) - fTextWidget.setSelection(selection.x, markOffset); - else - fTextWidget.setSelection(markOffset, 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 beginnig 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 whitepsace 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(); - IDocumentPartitioner partitioner= null; - - try { - - Point selection= getSelectedRange(); - IRegion block= getTextBlockFromSelection(selection); - ITypedRegion[] regions= d.computePartitioning(block.getOffset(), block.getLength()); - - 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 offset= regions[i].getOffset() + regions[i].getLength() - 1; - lines[j + 1]= (lines[j] == -1 ? -1 : d.getLineOfOffset(offset)); - lineCount += lines[j + 1] - lines[j] + 1; - } - - if (lineCount >= 20) { - partitioner= d.getDocumentPartitioner(); - if (partitioner != null) { - partitioner.disconnect(); - d.setDocumentPartitioner(null); - } - } - - // 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 (partitioner != null) { - partitioner.connect(d); - d.setDocumentPartitioner(partitioner); - } - - 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. - * - * Subclasses may override. - */ - 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) - */ - protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) { - if (fTextWidget == null) - return -1; - - try { - int offset= (startPosition == -1 ? startPosition : startPosition - getVisibleRegionOffset()); - int pos= getVisibleDocument().search(offset, findString, forwardSearch, caseSensitive, wholeWord); - if (pos > -1) { - int length= findString.length(); - if (redraws()) { - fTextWidget.setSelectionRange(pos, length); - internalRevealRange(pos, pos + length); - selectionChanged(pos, length); - } else { - setSelectedRange(pos + getVisibleRegionOffset(), length); - } - } - return pos + getVisibleRegionOffset(); - } catch (BadLocationException x) { - if (TRACE_ERRORS) - System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$ - } - - return -1; - } - - /** - * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean) - * @since 2.0 - */ - private int findAndSelectInRange(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, int rangeOffset, int rangeLength) { - if (fTextWidget == null) - return -1; - - try { - int offset; - if (forwardSearch && (startPosition == -1 || startPosition < rangeOffset)) { - offset= rangeOffset; - } else if (!forwardSearch && (startPosition == -1 || startPosition > rangeOffset + rangeLength)) { - offset= rangeOffset + rangeLength; - } else { - offset= startPosition; - } - offset -= getVisibleRegionOffset(); - - int pos= getVisibleDocument().search(offset, findString, forwardSearch, caseSensitive, wholeWord); - - int length = findString.length(); - if (pos != -1 && (pos + getVisibleRegionOffset() < rangeOffset || pos + getVisibleRegionOffset() + length > rangeOffset + rangeLength)) - pos= -1; - - if (pos > -1) { - if (redraws()) { - fTextWidget.setSelectionRange(pos, length); - internalRevealRange(pos, pos + length); - selectionChanged(pos, length); - } else { - setSelectedRange(pos + getVisibleRegionOffset(), length); - } - } - return pos + getVisibleRegionOffset(); - } 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 - */ - public void setTextColor(Color color) { - if (color != null) - setTextColor(color, 0, getDocument().getLength(), true); - } - - /* - * @see ITextViewer#setTextColor - */ - 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; - - 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) { - - fTextWidget.setStyleRange(range); - Iterator e= presentation.getNonDefaultStyleRangeIterator(); - while (e.hasNext()) { - range= (StyleRange) e.next(); - fTextWidget.setStyleRange(range); - } - - } else { - - Iterator e= presentation.getAllStyleRangeIterator(); - - // use optimized StyledText - StyleRange[] ranges= new StyleRange[presentation.getDenumerableRanges()]; - for (int i= 0; i < ranges.length; i++) - ranges[i]= (StyleRange) e.next(); - - IRegion region= presentation.getCoverage(); - fTextWidget.replaceStyleRanges(region.getOffset(), region.getLength(), 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 - */ - public void changeTextPresentation(TextPresentation presentation, boolean controlRedraw) { - - if (presentation == null) - return; - - presentation.setResultWindow(internalGetVisibleRegion()); - if (presentation.isEmpty() || fTextWidget == null) - return; - - if (controlRedraw) - fTextWidget.setRedraw(false); - - if (fReplaceTextPresentation) - TextPresentation.applyTextPresentation(presentation, fTextWidget); - else - addPresentation(presentation); - - if (controlRedraw) - fTextWidget.setRedraw(true); - } - - /* - * @see ITextViewer#getFindReplaceTarget() - */ - public IFindReplaceTarget getFindReplaceTarget() { - if (fFindReplaceTarget == null) - fFindReplaceTarget= new FindReplaceTarget(); - return fFindReplaceTarget; - } - - /* - * @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 { - if (fMarkPosition == null) { - - IDocument document= getDocument(); - if (document == null) - return; - - if (offset < 0 || offset > document.getLength()) - return; - - try { - Position position= new Position(offset); - document.addPosition(MARK_POSITION_CATEGORY, position); - fMarkPosition= position; - - } catch (BadLocationException e) { - return; - } catch (BadPositionCategoryException e) { - return; - } - - } else { - - IDocument document= getDocument(); - if (document == null) { - fMarkPosition= null; - return; - } - - if (offset < 0 || offset > document.getLength()) - return; - - fMarkPosition.setOffset(offset); - fMarkPosition.undelete(); - } - - markChanged(fMarkPosition.offset - getVisibleRegionOffset(), 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); - } - - /** - * Enables the redrawing of this text viewer. Subclasses may extend. - * @since 2.0 - */ - protected void enabledRedrawing() { - if (fDocumentAdapter instanceof IDocumentAdapterExtension) { - IDocumentAdapterExtension extension= (IDocumentAdapterExtension) fDocumentAdapter; - StyledText textWidget= getTextWidget(); - if (textWidget != null && !textWidget.isDisposed()) { - int topPixel= textWidget.getTopPixel(); - extension.resumeForwardingDocumentChanges(); - if (topPixel > -1) { - try { - textWidget.setTopPixel(topPixel); - } catch (IllegalArgumentException x) { - // changes don't allow for the previous top pixel - } - } - } - } - - setSelectedRange(fDocumentSelection.x, fDocumentSelection.y); - revealRange(fDocumentSelection.x, fDocumentSelection.y); - - if (fTextWidget != null && !fTextWidget.isDisposed()) - fTextWidget.setRedraw(true); - - fireRedrawChanged(); - } - - /** - * Disables the redrawing of this text viewer. Subclasses may extend. - * @since 2.0 - */ - protected void disableRedrawing() { - - fDocumentSelection= getSelectedRange(); - - 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) { - if (!redraw) { - if (fRedrawCounter == 0) - disableRedrawing(); - ++ fRedrawCounter; - } else { - -- fRedrawCounter; - if (fRedrawCounter == 0) - enabledRedrawing(); - } - } - - /** - * 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. - * @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; - } -} 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 426bdb67db8..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewerHoverManager.java +++ /dev/null @@ -1,300 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -import org.eclipse.swt.custom.StyledText; -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 { - - /** 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(); - - - /** - * 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; - } - } - } - }; - } - - /** - * Determines all necessary details and delegates the computation into - * a background thread. - */ - protected void computeInformation() { - - Point location= getHoverEventLocation(); - int offset= computeOffsetAtLocation(location.x, location.y); - if (offset == -1) { - setInformation(null, null); - return; - } - - final ITextHover hover= fTextViewer.getTextHover(offset); - 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() { - public void run() { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=17693 - try { - - if (fThread != null) { - String information= hover.getHoverInfo(fTextViewer, region); - setInformation(information, area); - } else { - setInformation(null, null); - } - - } finally { - synchronized (fMutex) { - if (fTextViewer != null) - fTextViewer.removeTextListener(fStopper); - fThread= 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) { - - StyledText styledText= fTextViewer.getTextWidget(); - IDocument document= fTextViewer.getVisibleDocument(); - - if (document == null) - return -1; - - int line= (y + styledText.getTopPixel()) / styledText.getLineHeight(); - int lineCount= document.getNumberOfLines(); - - if (line > lineCount - 1) - line= lineCount - 1; - - if (line < 0) - line= 0; - - try { - - IRegion lineInfo= document.getLineInformation(line); - int low= lineInfo.getOffset(); - int high= low + lineInfo.getLength(); - - int lookup= styledText.getLocationAtOffset(low).x; - int guess= low; - int guessDelta= Math.abs(lookup - x); - - for (int i= low + 1; i < high; i++) { - lookup= styledText.getLocationAtOffset(i).x; - int delta= Math.abs(lookup - x); - if (delta < guessDelta) { - guess= i; - guessDelta= delta; - } - } - - return guess + fTextViewer.getVisibleRegionOffset(); - - } catch (BadLocationException 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) { - - StyledText styledText= fTextViewer.getTextWidget(); - - IRegion visibleRegion= fTextViewer.getVisibleRegion(); - int start= region.getOffset() - visibleRegion.getOffset(); - int end= start + region.getLength(); - if (end > visibleRegion.getLength()) - end= visibleRegion.getLength(); - - 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); - } - - /* - * @see AbstractInformationControlManager#showInformationControl(Rectangle) - */ - protected void showInformationControl(Rectangle subjectArea) { - if (fTextViewer != null && fTextViewer.requestWidgetToken(this)) - super.showInformationControl(subjectArea); - } - - /* - * @see AbstractInformationControlManager#hideInformationControl() - */ - protected void hideInformationControl() { - try { - 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) { - super.hideInformationControl(); - return true; - } -} - 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 c5ca956ac6a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java +++ /dev/null @@ -1,230 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.IInformationControl; -import org.eclipse.jface.text.IInformationControlCreator; -import org.eclipse.jface.util.Assert; - - - -/** - * 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) { - } - }; - - - private Table fProposalTable; - private Thread fThread; - private boolean fIsReset= false; - - private Object fMutex= new Object(); - private Object fStartSignal; - - private SelectionListener fSelectionListener= new TableSelectionListener(); - 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); - 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() { - - 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) { - } - - 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(); - } - - // 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/text/contentassist/CompletionProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java deleted file mode 100644 index a33cf7f0265..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.util.Assert; - - - -/** - * The standard implementation of the <code>ICompletionProposal</code> interface. - */ -public final class CompletionProposal implements ICompletionProposal { - - private String fDisplayString; - private String fReplacementString; - private int fReplacementOffset; - private int fReplacementLength; - private int fCursorPosition; - private Image fImage; - private IContextInformation fContextInformation; - 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 contentInformation 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 - */ - public void apply(IDocument document) { - try { - document.replace(fReplacementOffset, fReplacementLength, fReplacementString); - } catch (BadLocationException x) { - // ignore - } - } - - /* - * @see ICompletionProposal#getSelection - */ - 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 da95fcc306b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java +++ /dev/null @@ -1,603 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.custom.StyledText; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -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.text.IDocument; -import org.eclipse.jface.text.ITextViewer; - - - -/** - * 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 - */ -class CompletionProposalPopup implements IContentAssistListener { - - private ITextViewer fViewer; - private ContentAssistant fContentAssistant; - private AdditionalInfoController fAdditionalInfoController; - - private PopupCloser fPopupCloser= new PopupCloser(); - private Shell fProposalShell; - private Table fProposalTable; - private boolean fInserting= false; - - private long fInvocationCounter= 0; - private ICompletionProposal[] fFilteredProposals; - private ICompletionProposal[] fComputedProposals; - private int fInvocationOffset; - private int fFilterOffset; - - private String fLineDelimiter; - - - /** - * 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 CompletionProposalPopup(ContentAssistant contentAssistant, ITextViewer viewer, AdditionalInfoController 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) { - final StyledText styledText= fViewer.getTextWidget(); - BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() { - public void run() { - - - fInvocationOffset= fViewer.getSelectedRange().x; - 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, fInvocationOffset); - - else { - - if (fLineDelimiter == null) - fLineDelimiter= styledText.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) { - 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= fViewer.getTextWidget(); - fProposalShell= new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE ); - fProposalTable= new Table(fProposalShell, SWT.H_SCROLL | SWT.V_SCROLL); - - fProposalTable.setLocation(0, 0); - 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); - 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) { - // 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) { - selectProposal(); - } - }); - - fPopupCloser.install(fContentAssistant, fProposalTable); - - 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 (i < 0 || i >= fFilteredProposals.length) - return null; - return fFilteredProposals[i]; - } - - /** - * Takes the selected proposal and applies it. - * @since 2.0 - */ - private void selectProposal() { - ICompletionProposal p= getSelectedProposal(); - hide(); - if (p != null) - insertProposal(p, (char) 0, 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.0 - */ - private void insertProposal(ICompletionProposal p, char trigger, int offset) { - - fInserting= true; - - try { - IDocument document= fViewer.getDocument(); - - 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); - } - - } finally { - 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() { - if (Helper.okToUse(fProposalShell)) { - - fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR); - - fPopupCloser.uninstall(); - fProposalShell.setVisible(false); - fProposalShell.dispose(); - fProposalShell= null; - } - - fFilteredProposals= null; - } - - /** - *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 (Helper.okToUse(fProposalTable)) { - - 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); - fProposalTable.setRedraw(true); - } - } - - /** - * 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(); - int caret= text.getCaretOffset(); - Point p= text.getLocationAtOffset(caret); - p= new Point(p.x, p.y + text.getLineHeight()); - return text.toDisplay(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, ContentAssistant.PROPOSAL_SELECTOR)) { - fProposalShell.setVisible(true); - if (fAdditionalInfoController != null) { - 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; - switch (e.keyCode) { - - case SWT.ARROW_LEFT : - case SWT.ARROW_RIGHT : - filterProposal(); - 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; - - case SWT.CTRL : - case SWT.SHIFT : - return true; - - default : - hide(); - return true; - } - - selectProposal(newSelection); - - e.doit= false; - return false; - - } else { - - switch (key) { - case 0x1B : // Esc - e.doit= false; - hide(); - break; - - case 0x0D : // Enter - e.doit= false; - selectProposal(); - break; - - default: - - if ('\t' == key) { - e.doit= false; - fProposalShell.setFocus(); - return false; - } - - 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, 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 - * @since 2.0 - */ - private void selectProposal(int index) { - 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) { - if (!fInserting) - filterProposal(); - } - - /** - * Filters the displayed proposal based on the given cursor position and the - * offset of the original invocation of the content assistant. - */ - private void filterProposal() { - ++ 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= (offset == -1 ? null : computeFilteredProposals(offset)); - 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 - * @return the set of filtered proposals - * @since 2.0 - */ - private ICompletionProposal[] computeFilteredProposals(int offset) { - - if (offset == fInvocationOffset) - 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= fViewer.getDocument(); - int length= proposals.length; - List filtered= new ArrayList(length); - for (int i= 0; i < length; i++) { - 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; - } -} - - 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 f174ac291a8..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java +++ /dev/null @@ -1,1377 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.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.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IEventConsumer; -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.IWidgetTokenOwner; - -import org.eclipse.jface.util.Assert; - - - -/** - * 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, IWidgetTokenKeeper { - - /** - * 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 (Helper.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 (Helper.okToUse(w)) { - - Control shell= w.getShell(); - if (Helper.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) { - Control control= fViewer.getTextWidget(); - Display d= control.getDisplay(); - d.asyncExec(new Runnable() { - public void run() { - if (!fProposalPopup.hasFocus() && !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(); - } - - /** - * 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, 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 verifyKey(VerifyEvent e) { - - int showStyle; - int pos= fViewer.getSelectedRange().x; - char[] activation= getCompletionProposalAutoActivationCharacters(fViewer.getDocument(), pos); - - if (contains(activation, e.character) && !fProposalPopup.isActive()) - showStyle= SHOW_PROPOSALS; - else { - activation= getContextInformationAutoActivationCharacters(fViewer.getDocument(), 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. - public final static int LAYOUT_PROPOSAL_SELECTOR= 0; - public final static int LAYOUT_CONTEXT_SELECTOR= 1; - 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 shiftLeftLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) { - if (location.x + shellBounds.width > displayBounds.width) - location.x= displayBounds.width - shellBounds.width; - } - - protected void shiftDownLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) { - if (location.y < displayBounds.y) - location.y= displayBounds.y; - } - - protected void shiftUpLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) { - if (location.y + shellBounds.height > displayBounds.height) - location.y= displayBounds.height - shellBounds.height; - } - - 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; - - shiftLeftLocation(location, shellBounds, displayBounds); - shiftDownLocation(location, shellBounds, displayBounds); - - return location; - } - - protected Point getBelowLocation(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 + text.getLineHeight(); - shiftLeftLocation(location, shellBounds, displayBounds); - shiftUpLocation(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(); - shiftLeftLocation(p, shellBounds, displayBounds); - shiftUpLocation(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 event the verify event - * @see VerifyKeyListener#verifyKey - */ - 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) - return; - } - } - } - - /* - * @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; - } - } - } - }; - - - // Content-Assist Listener types - final static int CONTEXT_SELECTOR= 0; - final static int PROPOSAL_SELECTOR= 1; - final static int CONTEXT_INFO_POPUP= 2; - - private IInformationControlCreator fInformationControlCreator; - private int fAutoActivationDelay= 500; - private boolean fIsAutoActivated= false; - private boolean fIsAutoInserting= false; - private int fProposalPopupOrientation= PROPOSAL_OVERLAY; - private int fContextInfoPopupOrientation= CONTEXT_INFO_ABOVE; - private Map fProcessors; - - 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 fKeyListenerHooked= false; - private IContentAssistListener[] fListeners= new IContentAssistListener[4]; - - /** - * 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. - */ - public ContentAssistant() { - } - - /** - * 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 (Helper.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 (Helper.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(); - - AdditionalInfoController controller= null; - if (fInformationControlCreator != null) - controller= new AdditionalInfoController(fInformationControlCreator, Math.round(fAutoActivationDelay * 1.5f)); - - fContextInfoPopup= new ContextInformationPopup(this, fViewer); - fProposalPopup= new CompletionProposalPopup(this, fViewer, controller); - - manageAutoActivation(fIsAutoActivated); - } - - /* - * @see IContentAssist#uninstall - */ - public void uninstall() { - - if (fProposalPopup != null) - fProposalPopup.hide(); - - if (fContextInfoPopup != null) - fContextInfoPopup.hide(); - - manageAutoActivation(false); - - 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); - } - return false; - } - 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 (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 (Helper.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(IContentAssistListener 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 (Helper.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); - } - - /* - * @see IContentAssist#showContextInformation - */ - public String showContextInformation() { - return fContextInfoPopup.showContextProposals(false); - } - - /** - * 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 document the document - * @param position a position within the document - * @return a content-assist processor or <code>null</code> if none exists - */ - private IContentAssistProcessor getProcessor(IDocument document, int position) { - try { - String type= document.getContentType(position); - 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) { - fLastErrorMessage= null; - - ICompletionProposal[] result= null; - - IContentAssistProcessor p= getProcessor(viewer.getDocument(), 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 - */ - IContextInformation[] computeContextInformation(ITextViewer viewer, int position) { - fLastErrorMessage= null; - - IContextInformation[] result= null; - - IContentAssistProcessor p= getProcessor(viewer.getDocument(), 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 document the document - * @param position a document position - * @return an validator - * - * @see IContentAssistProcessor#getContextInformationValidator - */ - IContextInformationValidator getContextInformationValidator(IDocument document, int position) { - IContentAssistProcessor p= getProcessor(document, position); - if (p != null) - return p.getContextInformationValidator(); - 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 document the document - * @param position a document position - * @return a presenter - * @since 2.0 - */ - IContextInformationPresenter getContextInformationPresenter(IDocument document, int position) { - IContextInformationValidator validator= getContextInformationValidator(document, position); - 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 document the document - * @param position a document position - * @return the auto activation characters - * - * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters - */ - private char[] getCompletionProposalAutoActivationCharacters(IDocument document, int position) { - IContentAssistProcessor p= getProcessor(document, position); - if (p != null) - return p.getCompletionProposalAutoActivationCharacters(); - return 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 document the document - * @param position a document position - * @return the auto activation characters - * - * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters - */ - private char[] getContextInformationAutoActivationCharacters(IDocument document, int position) { - IContentAssistProcessor p= getProcessor(document, position); - if (p != null) - return p.getContextInformationAutoActivationCharacters(); - return null; - } - - /* - * @see org.eclipse.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner) - * @since 2.0 - */ - public boolean requestWidgetToken(IWidgetTokenOwner owner) { - return false; - } -} - 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 8dbc83dd1e4..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.jface.util.Assert; - - -/** - * A default implementation of the <code>IContextInformation</code> interface. - */ -public final class ContextInformation implements IContextInformation { - - private String fContextDisplayString; - private String fInformationDisplayString; - 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 - */ - 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 9f87bc2082a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java +++ /dev/null @@ -1,623 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.contentassist; -
-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.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.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 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 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; - }; - - private ITextViewer fViewer; - private ContentAssistant fContentAssistant; - private int fListenerCount= 0; - - 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(); - - - /** - * 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; - } - - /** - * 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.getDocument(), 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.getDocument(), 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, ContentAssistant.CONTEXT_INFO_POPUP)) { - 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 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 (Helper.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 (Helper.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, ContentAssistant.CONTEXT_INFO_POPUP); - - fContextInfoPopup.setVisible(false); - fContextInfoPopup.dispose(); - fContextInfoPopup= null; - - if (fTextPresentation != null) { - fTextPresentation.clear(); - fTextPresentation= null; - } - } - } - } - - /** - * 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= 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, 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= fViewer.getSelectedRange().x; - internalShowContextInfo(fContextSelectorInput[i], position); - } - - /** - * Sets the contexts in the context selector to the given set. - * - * @param contexts teh 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); - } - - /** - * Hodes 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; - } - } - - /** - *Returns whether the context selector has the focus. - * @return <code>true</code> if teh 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; - - case SWT.CTRL: - case SWT.SHIFT: - return true; - default: - 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; - case SWT.CTRL: - case SWT.SHIFT: - break; - default: - 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 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 (Helper.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(); - } - } - } - }); - } -}
\ No newline at end of file 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 79def403c9b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 { - - private IContentAssistProcessor fProcessor; - private IContextInformation fContextInformation; - private ITextViewer fViewer; - - /** - * Creates a new context information validator which is ready to be installed on - * a particular context information. - */ - public ContextInformationValidator(IContentAssistProcessor processor) { - fProcessor= processor; - } - - /* - * @see IContextInformationValidator#install - */ - public void install(IContextInformation contextInformation, ITextViewer viewer, int position) { - fContextInformation= contextInformation; - fViewer= viewer; - } - - /* - * @see IContentAssistTipCloser#isContextInformationValid - */ - 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; - } -}
\ No newline at end of file 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 7f74688820b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/Helper.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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()); - } -}
\ No newline at end of file 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 01c1babdaf4..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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. - * - * @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 160e833d617..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension.java +++ /dev/null @@ -1,66 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 - */ - 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/IContentAssistListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java deleted file mode 100644 index 5b3166fc0ac..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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. - * - * @return <code>true</code> if processing should be continued by additional listeners - * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey - */ - public boolean verifyKey(VerifyEvent event); -}
\ No newline at end of file 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 3a0783f808d..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistProcessor.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 documentPosition 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 documentPosition 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> - * - * Because of http://dev.eclipse.org/bugs/show_bug.cgi?id=13926 the object returned - * by this method should also implement <code>IContextInformationPresenter</code>. - * @see IContextInformationPresenter - * - * @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 74fcd27e987..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistant.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -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); -}
\ No newline at end of file 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 bbf4efec1ad..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformation.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 - */ - 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 d34e2435cf6..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationExtension.java +++ /dev/null @@ -1,29 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 d0b8783103f..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenter.java +++ /dev/null @@ -1,48 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 information the context information to be styled - * @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); -}
\ No newline at end of file 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 661023c92a4..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidator.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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. <p> - * - * @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); -}
\ No newline at end of file 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 5b93bed4921..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -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 41f264a12cf..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.eclipse.jface.text.contentassist; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -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 assist should be terminated and all - * associated windows be closed. - */ -class PopupCloser implements FocusListener, SelectionListener { - - private ContentAssistant fContentAssistant; - private Table fTable; - private ScrollBar fScrollbar; - private boolean fScrollbarClicked= false; - - 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); - } - } - - public void uninstall() { - if (Helper.okToUse(fTable)) { - fTable.removeFocusListener(this); - if (fScrollbar != null) - fScrollbar.removeSelectionListener(this); - } - } - - // SelectionListener - public void widgetSelected(SelectionEvent e) { - fScrollbarClicked= true; - } - - public void widgetDefaultSelected(SelectionEvent e) { - fScrollbarClicked= true; - } - - // FocusListener - public void focusGained(FocusEvent e) { - } - - 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); - } - }); - } -}
\ No newline at end of file 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 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> -</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 a1b2358ee38..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java +++ /dev/null @@ -1,677 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.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.IPositionUpdater; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.util.Assert; - - -/** - * Standard implementation of <code>IContentFormatter</code>. - * The formatter supports two operation modi: 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 postions - * 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; - - protected PositionReference(Position position, boolean refersToOffset, String category) { - fPosition= position; - fRefersToOffset= refersToOffset; - fCategory= category; - } - - /** - * Returns the offset of the referenced position. - */ - protected int getOffset() { - return fPosition.getOffset(); - } - - /** - * Manipulates the offset of the referenced position. - */ - protected void setOffset(int offset) { - fPosition.setOffset(offset); - } - - /** - * Returns the length of the referenced position. - */ - protected int getLength() { - return fPosition.getLength(); - } - - /** - * Manipulates the length of the referenced position. - */ - protected void setLength(int length) { - fPosition.setLength(length); - } - - /** - * Returns whether this reference points to the offset or endoffset - * of the references position. - */ - protected boolean refersToOffset() { - return fRefersToOffset; - } - - /** - * Returns the category of the referenced position. - */ - protected String getCategory() { - return fCategory; - } - - /** - * Returns the referenced position. - */ - protected Position getPosition() { - return fPosition; - } - - /** - * Returns 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 adapt all to update the - * remembered partitions. - * - * @see IPositionUpdater - * @see DefaultPositionUpdater - */ - class NonDeletingPositionUpdater extends DefaultPositionUpdater { - - 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 regularily 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 { - - private int[] fPositions; - private int fOffset; - - 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; - - - - /** - * Creates a new content formatter. The content formatter operates by default - * in the partition-aware mode. There are no preconfigured formatting strategies. - */ - public ContentFormatter() { - } - - /** - * 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 - */ - public void setPartitionManagingPositionCategories(String[] categories) { - fPartitionManagingCategories= categories; - } - - /** - * 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 - */ - public IFormattingStrategy getFormattingStrategy(String contentType) { - - Assert.isNotNull(contentType); - - if (fStrategies == null) - return null; - - return (IFormattingStrategy) fStrategies.get(contentType); - } - - /* - * @see IContentFormatter#format - */ - public void format(IDocument document, IRegion region) { - if (fIsPartitionAware) - formatPartitions(document, region); - else - formatRegion(document, region); - } - - /** - * Determines the partitioning of the given region of the document. - * Informs for each partition about the start, the process, and the - * termination of the formatting session. - */ - private void formatPartitions(IDocument document, IRegion region) { - - addPartitioningUpdater(document); - - try { - - TypedPosition[] ranges= getPartitioning(document, region); - if (ranges != null) { - start(ranges, getIndentation(document, region.getOffset())); - format(document, ranges); - stop(ranges); - } - - } catch (BadLocationException x) { - } - - removePartitioningUpdater(document); - } - - /** - * Informs for the given region about the start, the process, and - * the termination of the formatting session. - */ - private void formatRegion(IDocument document, IRegion region) { - - IFormattingStrategy strategy= getFormattingStrategy(IDocument.DEFAULT_CONTENT_TYPE); - if (strategy != null) { - strategy.formatterStarts(getIndentation(document, region.getOffset())); - format(document, 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 stratgies might rely on each - * other, calling them in reversed order is not an option.) - * - * @param document the document - * @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 - */ - private TypedPosition[] getPartitioning(IDocument document, IRegion region) throws BadLocationException { - - ITypedRegion[] regions= document.computePartitioning(region.getOffset(), region.getLength()); - TypedPosition[] positions= new TypedPosition[regions.length]; - - for (int i= 0; i < regions.length; i++) { - positions[i]= new TypedPosition(regions[i]); - try { - document.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 document to document to be formatted - * @param ranges the partitioning of the document region to be formatted - */ - private void format(final IDocument document, TypedPosition[] ranges) { - for (int i= 0; i < ranges.length; i++) { - IFormattingStrategy s= getFormattingStrategy(ranges[i].getType()); - if (s != null) { - format(document, 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 upcoming change, the affected positions are removed to avoid that they - * are regularily 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 happend. - * - * @param document the document to be formatted - * @param strategy the strategy to be used - * @param region the region to be formatted - */ - private void format(final IDocument document, IFormattingStrategy strategy, TypedPosition region) { - try { - - final int offset= region.getOffset(); - int length= region.getLength(); - - String content= document.get(offset, length); - final int[] positions= getAffectedPositions(document, offset, length); - String formatted= strategy.format(content, isLineStart(document, offset), getIndentation(document, offset), positions); - - IPositionUpdater first= new RemoveAffectedPositions(); - document.insertPositionUpdater(first, 0); - IPositionUpdater last= new UpdateAffectedPositions(positions, offset); - document.addPositionUpdater(last); - - document.replace(offset, length, formatted); - - document.removePositionUpdater(first); - document.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. - * - * @param document the document to be formatted - */ - private void addPartitioningUpdater(IDocument document) { - fPartitioningUpdater= new NonDeletingPositionUpdater(PARTITIONING); - document.addPositionCategory(PARTITIONING); - document.addPositionUpdater(fPartitioningUpdater); - } - - /** - * Removes the formatter's internal position updater and category. - * - * @param document the document that has been formatted - */ - private void removePartitioningUpdater(IDocument document) { - - try { - - document.removePositionUpdater(fPartitioningUpdater); - document.removePositionCategory(PARTITIONING); - fPartitioningUpdater= null; - - } catch (BadPositionCategoryException x) { - // should not happen - } - } - - /** - * 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; - - if (fPartitionManagingCategories != null) { - for (int i= 0; i < fPartitionManagingCategories.length; i++) { - if (fPartitionManagingCategories[i].equals(category)) - return true; - } - } - - return false; - } - - /** - * Determines all embracing, overlapping, and follow up positions - * for the given region of the document. - * - * @param document the document to be formatted - * @param offset the offset of the document region to be formatted - * @param length the length of the document to be formatted - */ - private void determinePositionsToUpdate(IDocument document, int offset, int length) { - - String[] categories= document.getPositionCategories(); - if (categories != null) { - for (int i= 0; i < categories.length; i++) { - - if (ignoreCategory(categories[i])) - continue; - - try { - - Position[] positions= document.getPositions(categories[i]); - - for (int j= 0; j < positions.length; j++) { - - Position p= (Position) 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 document the document to be formatted - * @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 - */ - private int[] getAffectedPositions(IDocument document, int offset, int length) { - - fOverlappingPositionReferences= new ArrayList(); - - determinePositionsToUpdate(document, 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 - */ - private void updateAffectedPositions(IDocument document, int[] positions, int offset) { - - if (positions.length == 0) - return; - - Map added= new HashMap(positions.length * 2); - - 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()); - - if (added.get(r.getPosition()) == null) { - try { - document.addPosition(r.getCategory(), r.getPosition()); - added.put(r.getPosition(), r.getPosition()); - } catch (BadPositionCategoryException x) { - // can not happen - } catch (BadLocationException x) { - // should not happen - } - } - - } - - fOverlappingPositionReferences= null; - } - - /** - * Returns the indentation of the line of the given offset. - * - * @param document the document - * @param offset the offset - * @return the indentation of the line of the offset - */ - private String getIndentation(IDocument document, int offset) { - - try { - int start= document.getLineOfOffset(offset); - start= document.getLineOffset(start); - - int end= start; - char c= document.getChar(end); - while ('\t' == c || ' ' == c) - c= document.getChar(++end); - - return document.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 document the 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 - */ - private boolean isLineStart(IDocument document, int offset) throws BadLocationException { - int start= document.getLineOfOffset(offset); - start= document.getLineOffset(start); - return (start == offset); - } -} 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 329e8c92dc3..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatter.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.eclipse.jface.text.formatter; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -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/IFormattingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java deleted file mode 100644 index 2db39452d2b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java +++ /dev/null @@ -1,55 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.formatter; - - -/** - * An 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(); -}
\ No newline at end of file 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 33f16a7de0c..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/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 text formatter add-on for an <tt>ITextViewer</tt>. -A text formatter changes the formatting of 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>). -</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 74375c75013..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenter.java +++ /dev/null @@ -1,66 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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. - * - * @return an optional error message if - */ - 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/IInformationProvider.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java deleted file mode 100644 index e9be43fdac1..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 - */ - String getInformation(ITextViewer textViewer, IRegion subject); -} - 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 332e8afa151..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java +++ /dev/null @@ -1,393 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.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.ITextViewer; -import org.eclipse.jface.text.IViewportListener; -import org.eclipse.jface.text.IWidgetTokenKeeper; -import org.eclipse.jface.text.IWidgetTokenOwner; - -import org.eclipse.jface.util.Assert; - -/** - * 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, IWidgetTokenKeeper { - - /** - * 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.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; - - - /** - * 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. - * - * @param creator the information control creator to be used - */ - public InformationPresenter(IInformationControlCreator creator) { - super(creator); - setCloser(new Closer()); - takesFocusWhenVisible(true); - } - - /** - * 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); - } - - /* - * @see AbstractInformationControlManager#computeInformation() - */ - protected void computeInformation() { - int offset= fTextViewer.getSelectedRange().x; - if (offset == -1) - return; - - - IInformationProvider provider= null; - try { - IDocument document= fTextViewer.getDocument(); - String type= document.getContentType(offset); - provider= getInformationProvider(type); - } catch (BadLocationException x) { - } - if (provider == null) - return; - - IRegion subject= provider.getSubject(fTextViewer, offset); - if (subject == null) - return; - - 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) { - - StyledText styledText= fTextViewer.getTextWidget(); - - IRegion visible= fTextViewer.getVisibleRegion(); - int start= region.getOffset() - visible.getOffset(); - int end= start + region.getLength(); - - 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); - } - - /* - * @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 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; - } -} - 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/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. 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 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> 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 3f2ba767b02..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationDamager.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.eclipse.jface.text.presentation; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 neede to sucessfully 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 documentPartitioningChange indicates whether the given change changed the document's partitioning - * @return the computed damage - */ - IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged); -}
\ No newline at end of file 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 962e4b3ea5e..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.eclipse.jface.text.presentation; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -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 textViewer 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/IPresentationRepairer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java deleted file mode 100644 index 8217dcf95e5..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.jface.text.presentation; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 6981d42850f..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java +++ /dev/null @@ -1,465 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.presentation; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -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.IDocumentListener; -import org.eclipse.jface.text.IDocumentPartitioningListener; -import org.eclipse.jface.text.IDocumentPartitioningListenerExtension; -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.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.util.Assert; - - - -/** - * 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 { - - /** 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 { - - /** Set to <code>true</code> if between a document about to be changed and a changed event. */ - private boolean fDocumentChanging= false; - - /* - * @see ITextInputListener#inputDocumentAboutToBeChanged - */ - 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 - */ - public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { - - fDocumentChanging= false; - - 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 - */ - public void documentPartitioningChanged(IDocument document) { - if (!fDocumentChanging) - processDamage(new Region(0, document.getLength()), document); - else - fDocumentPartitioningChanged= true; - } - - /* - * @see IDocumentPartitioningListenerExtension#documentPartitioningChanged - * @since 2.0 - */ - public void documentPartitioningChanged(IDocument document, IRegion changedRegion) { - if (!fDocumentChanging) { - processDamage(new Region(changedRegion.getOffset(), changedRegion.getLength()), document); - } else { - fDocumentPartitioningChanged= true; - fChangedDocumentPartitions= changedRegion; - } - } - - /* - * @see IDocumentListener#documentAboutToBeChanged - */ - public void documentAboutToBeChanged(DocumentEvent e) { - - fDocumentChanging= true; - - try { - int offset= e.getOffset() + e.getLength(); - fRememberedPosition= new TypedPosition(e.getDocument().getPartition(offset)); - e.getDocument().addPosition(fPositionCategory, fRememberedPosition); - } catch (BadLocationException x) { - // can not happen - } catch (BadPositionCategoryException x) { - // should not happen on input elements - } - } - - /* - * @see IDocumentListener#documentChanged - */ - public void documentChanged(DocumentEvent e) { - try { - e.getDocument().removePosition(fPositionCategory, fRememberedPosition); - } catch (BadPositionCategoryException x) { - // can not happen on input documents - } - - fDocumentChanging= false; - } - - /* - * @see ITextListener#textChanged - */ - public void textChanged(TextEvent e) { - - if (!e.getViewerRedrawState()) - return; - - DocumentEvent de= e.getDocumentEvent(); - - if (de == null) { - - IDocument d= fViewer.getDocument(); - processDamage(new Region(0, d.getLength()), d); - - } else { - - IRegion damage= getDamage(de); - if (damage != null) - processDamage(damage, de.getDocument()); - } - - fDocumentPartitioningChanged= false; - fChangedDocumentPartitions= null; - } - }; - - /** 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 parititoning. */ - private IRegion fChangedDocumentPartitions= null; - - - /** - * Creates a new presentation reconciler. There are no damagers or repairers - * registered with this reconciler. - */ - public PresentationReconciler() { - super(); - fPositionCategory= TRACKED_PARTITION + hashCode(); - fPositionUpdater= new DefaultPositionUpdater(fPositionCategory); - } - - /** - * 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 - */ - public void install(ITextViewer viewer) { - Assert.isNotNull(viewer); - - fViewer= viewer; - fViewer.addTextInputListener(fInternalListener); - } - - /* - * @see IPresentationReconciler#uninstall - */ - public void uninstall() { - fViewer.removeTextInputListener(fInternalListener); - } - - /* - * @see IPresentationReconciler#getDamager - */ - public IPresentationDamager getDamager(String contentType) { - - if (fDamagers == null) - return null; - - return (IPresentationDamager) fDamagers.get(contentType); - } - - /* - * @see IPresentationReconciler#getRepairer - */ - 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 - */ - private 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 - */ - private 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 descritption as text presentation - */ - private TextPresentation createPresentation(IRegion damage, IDocument document) { - try { - - TextPresentation presentation= new TextPresentation(); - - ITypedRegion[] partitioning= document.computePartitioning(damage.getOffset(), damage.getLength()); - 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 - * @return the damaged caused by the change - */ - private IRegion getDamage(DocumentEvent e) { - - IRegion damage= null; - - try { - - ITypedRegion partition= e.getDocument().getPartition(e.getOffset()); - IPresentationDamager damager= getDamager(partition.getType()); - if (damager == null) - return null; - - IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged); - - if (!fDocumentPartitioningChanged) { - 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= d.getPartition(e.getOffset() + length); - int endOffset= partition.getOffset() + partition.getLength(); - if (endOffset == e.getOffset()) - return -1; - - int end= fRememberedPosition.getOffset() + fRememberedPosition.getLength(); - if (endOffset < end) - partition= d.getPartition(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 && !p.isEmpty()) - 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); - } -} 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/AbstractReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java deleted file mode 100644 index e64bcbb93ee..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java +++ /dev/null @@ -1,458 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.reconciler; - - -import org.eclipse.core.runtime.IProgressMonitor; - -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; - -import org.eclipse.jface.util.Assert; - - - -/** - * 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; - /** Has a change been applied */ - 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; - } - - /** - * Cancels the background thread. - */ - public void cancel() { - fCanceled= true; - synchronized (fDirtyRegionQueue) { - fDirtyRegionQueue.notifyAll(); - } - } - - /** - * 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(); - } - } - - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19525 - 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 (!fIsDirty) - continue; - - if (fReset) { - synchronized (this) { - fReset= false; - } - continue; - } - - DirtyRegion r= null; - synchronized (fDirtyRegionQueue) { - r= fDirtyRegionQueue.removeNextDirtyRegion(); - } - - fIsActive= true; - - if (fProgressMonitor != null) - fProgressMonitor.setCanceled(false); - - process(r); - - synchronized (this) { - fIsDirty= false; - } - - fIsActive= false; - } - } - }; - - /** - * Internal document listener and text input listener. - */ - class Listener implements IDocumentListener, ITextInputListener { - - /* - * @see IDocumentListener#documentAboutToBeChanged - */ - public void documentAboutToBeChanged(DocumentEvent e) { - } - - /* - * @see IDocumentListener#documentChanged - */ - public void documentChanged(DocumentEvent e) { - - if (fProgressMonitor != null && fThread.isActive()) - fProgressMonitor.setCanceled(true); - - if (fIsIncrementalReconciler) - createDirtyRegion(e); - - fThread.reset(); - } - - /* - * @see ITextInputListener#inputDocumentAboutToBeChanged - */ - 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); - } - } - - fDocument= null; - } - } - - /* - * @see ITextInputListener#inputDocumentChanged - */ - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - - if (newInput == null) - return; - - fDocument= newInput; - reconcilerDocumentChanged(fDocument); - - fDocument.addDocumentListener(this); - - forceReconciling(); - } - }; - - /** 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 milli seconds 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 - */ - public void install(ITextViewer textViewer) { - - Assert.isNotNull(textViewer); - - fViewer= textViewer; - - fListener= new Listener(); - fViewer.addTextInputListener(fListener); - - fDirtyRegionQueue= new DirtyRegionQueue(); - fThread= new BackgroundThread(getClass().getName()); - } - - /* - * @see IReconciler#uninstall - */ - public void uninstall() { - if (fListener != null) { - - fViewer.removeTextInputListener(fListener); - if (fDocument != null) fDocument.removeDocumentListener(fListener); - fListener= null; - - // 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())); - } - } - - /** - * 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 (fIsIncrementalReconciler) { - DocumentEvent e= new DocumentEvent(fDocument, 0, 0, fDocument.get()); - createDirtyRegion(e); - } - - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19135 - if (fThread == null) - return; - - if (!fThread.isAlive()) - fThread.start(); - 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 01c57a65a0f..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.eclipse.jface.text.reconciler; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.jface.text.ITypedRegion; - -/** - * A dirty region describes a document range which has been changed. - */ -public class DirtyRegion implements ITypedRegion { - - /** Definitions of edit types */ - final static public String INSERT= "__insert"; //$NON-NLS-1$ - 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 6e4e942ba48..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegionQueue.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.eclipse.jface.text.reconciler; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -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/IReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java deleted file mode 100644 index fa3d8e530a5..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.eclipse.jface.text.reconciler; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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/IReconcilingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java deleted file mode 100644 index 8292a23ae9f..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.eclipse.jface.text.reconciler; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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); -}
\ No newline at end of file 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 971fb681e07..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategyExtension.java +++ /dev/null @@ -1,45 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 2fd0a670bee..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/MonoReconciler.java +++ /dev/null @@ -1,102 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.reconciler; - - -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.util.Assert; - -/** - * Standard implementation of <code>IReconciler</code>. The reconciler - * is configured with a single <code>IReconcilingStrategy</code> that is - * used independ 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 - */ - 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 - fStrategy.reconcile(new Region(0, getDocument().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 cd8a3858058..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java +++ /dev/null @@ -1,185 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.BadLocationException; -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.TypedRegion; -import org.eclipse.jface.util.Assert; - -/** - * 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 { - - /** The map of reconciling strategies */ - private Map fStrategies; - - /** - * 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. - */ - public Reconciler() { - super(); - } - - /** - * 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 - */ - 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= null; - try { - regions= getDocument().computePartitioning(region.getOffset(), region.getLength()); - } catch (BadLocationException x) { - regions= new TypedRegion[0]; - } - - 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() { - - IRegion region= new Region(0, getDocument().getLength()); - - ITypedRegion[] regions= null; - try { - regions= getDocument().computePartitioning(region.getOffset(), region.getLength()); - } catch (BadLocationException x) { - regions= new TypedRegion[0]; - } - - 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(); - } - } - } -} 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 reconciler provides generic synchronization support 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 c5a00bd6fd7..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.util.Assert; - -/** - * A buffered rule based scanner. The buffer always contains a section - * of a fixed size of the document to be scanned. - */ -public class BufferedRuleBasedScanner extends RuleBasedScanner { - - private final static int DEFAULT_BUFFER_SIZE= 500; - - private int fBufferSize= DEFAULT_BUFFER_SIZE; - private char[] fBuffer= new char[DEFAULT_BUFFER_SIZE]; - - private int fStart; - private int fEnd; - 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 - */ - 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); - - 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 1802efe11be..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java +++ /dev/null @@ -1,213 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.swt.custom.StyleRange; - -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; -import org.eclipse.jface.util.Assert; - - -/** - * 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; - } - - /* - * @see IPresentationDamager#setDocument - * @see IPresentationRepairer#setDocument - */ - 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 - */ - 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 - */ - 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; - 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(); - } else { - addRange(presentation, lastStart, length, lastAttribute); - 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 39601db06f4..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java +++ /dev/null @@ -1,518 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.rules; - - -import java.util.ArrayList; -import java.util.List; - -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.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; -import org.eclipse.jface.util.Assert; - - - -/** - * 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 { - - /** The position category this partitioner uses to store the document's partitioning information */ - 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= new DefaultPositionUpdater(CONTENT_TYPES_CATEGORY); - /** 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; - - - /** - * 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; - } - - /* - * @see IDocumentPartitioner#connect - */ - public void connect(IDocument document) { - Assert.isNotNull(document); - Assert.isTrue(!document.containsPositionCategory(CONTENT_TYPES_CATEGORY)); - - fDocument= document; - fDocument.addPositionCategory(CONTENT_TYPES_CATEGORY); - - 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(CONTENT_TYPES_CATEGORY, 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(CONTENT_TYPES_CATEGORY)); - - try { - fDocument.removePositionCategory(CONTENT_TYPES_CATEGORY); - } 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) - */ - public IRegion documentChanged2(DocumentEvent e) { - - try { - - IDocument d= e.getDocument(); - Position[] category= d.getPositions(CONTENT_TYPES_CATEGORY); - IRegion line= d.getLineInformationOfOffset(e.getOffset()); - int reparseStart= line.getOffset(); - int partitionStart= -1; - String contentType= null; - - int first= d.computeIndexInCategory(CONTENT_TYPES_CATEGORY, 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(CONTENT_TYPES_CATEGORY); - - 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(CONTENT_TYPES_CATEGORY, start, length) || - !contentType.equals(p.getType())))) { - - rememberRegion(p.offset, p.length); - d.removePosition(CONTENT_TYPES_CATEGORY, p); - ++ first; - - } else - break; - } - - // if position already exists we are done - if (d.containsPosition(CONTENT_TYPES_CATEGORY, start, length)) { - if (lastScannedPosition > e.getOffset()) - return createRegion(); - ++ first; - } else { - // insert the new type position - try { - d.addPosition(CONTENT_TYPES_CATEGORY, 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 - TypedPosition p; - first= d.computeIndexInCategory(CONTENT_TYPES_CATEGORY, lastScannedPosition); - while (first < category.length) { - p= (TypedPosition) category[first++]; - d.removePosition(CONTENT_TYPES_CATEGORY, 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(CONTENT_TYPES_CATEGORY, offset); - Position[] category= fDocument.getPositions(CONTENT_TYPES_CATEGORY); - - 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(CONTENT_TYPES_CATEGORY); - - if (category == null || category.length == 0) - return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); - - int index= fDocument.computeIndexInCategory(CONTENT_TYPES_CATEGORY, 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) { - - List list= new ArrayList(); - - try { - - int endOffset= offset + length; - - Position[] category= fDocument.getPositions(CONTENT_TYPES_CATEGORY); - - 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 (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 (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; - } - - /* - * @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; - } -} 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 6d8f55af59a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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); - } -}
\ No newline at end of file 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 e93f1a19049..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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 { - - - 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 90ae6c7597e..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java +++ /dev/null @@ -1,42 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 8e4dd59c46d..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPredicateRule.java +++ /dev/null @@ -1,47 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 eea49dfa23a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IRule.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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 c32d7ad8ee3..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IToken.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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(); -}
\ No newline at end of file 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 58b143d5482..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ITokenScanner.java +++ /dev/null @@ -1,58 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 0a905280c87..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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. - */ - boolean isWhitespace(char c); -}
\ No newline at end of file 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 dd2b36668c2..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWordDetector.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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. - */ - boolean isWordStart(char c); - - /** - * Returns whether the specified character is - * valid as a subsequent character in a word. - */ - boolean isWordPart(char c); -}
\ No newline at end of file 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 f247574684b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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) { - super(startSequence, endSequence, token, escapeCharacter, false); - } -}
\ No newline at end of file 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 a924522e058..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/NumberRule.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.jface.util.Assert; - - -/** - * An implementation of <code>IRule</code> capable of detecting a numerical value. - */ -public class NumberRule implements IRule { - - protected static final int UNDEFINED= -1; - - protected IToken fToken; - 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 - */ - 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; - } -}
\ No newline at end of file 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 82783699993..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java +++ /dev/null @@ -1,215 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.jface.util.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 { - - 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 end of line termines the pattern */ - protected boolean fBreaksOnEOL; - - /** - * 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 indicates whether the end of the line also termines 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; - } - - /** - * 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 - */ - 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(); - 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], false)) - return true; - } - } - } - scanner.unread(); - return true; - } - - /** - * 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; - } -}
\ No newline at end of file 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 283971f2f7f..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedDamagerRepairer.java +++ /dev/null @@ -1,49 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 9250aa72327..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java +++ /dev/null @@ -1,106 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 2a7cf435a53..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java +++ /dev/null @@ -1,520 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.List; - -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.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; -import org.eclipse.jface.util.Assert; - - - -/** - * 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 { - - /** The position category this partitioner uses to store the document's partitioning information */ - 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= new DefaultPositionUpdater(CONTENT_TYPES_CATEGORY); - /** 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; - - - /** - * 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; - } - - /* - * @see IDocumentPartitioner#connect - */ - public void connect(IDocument document) { - Assert.isNotNull(document); - Assert.isTrue(!document.containsPositionCategory(CONTENT_TYPES_CATEGORY)); - - fDocument= document; - fDocument.addPositionCategory(CONTENT_TYPES_CATEGORY); - - 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(CONTENT_TYPES_CATEGORY, 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(CONTENT_TYPES_CATEGORY)); - - try { - fDocument.removePositionCategory(CONTENT_TYPES_CATEGORY); - } 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(CONTENT_TYPES_CATEGORY); - 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(CONTENT_TYPES_CATEGORY, 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(CONTENT_TYPES_CATEGORY); - - 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(CONTENT_TYPES_CATEGORY, start, length) || - !contentType.equals(p.getType())))) { - - rememberRegion(p.offset, p.length); - d.removePosition(CONTENT_TYPES_CATEGORY, p); - ++ first; - - } else - break; - } - - // if position already exists we are done - if (d.containsPosition(CONTENT_TYPES_CATEGORY, start, length)) - return createRegion(); - - // insert the new type position - try { - d.addPosition(CONTENT_TYPES_CATEGORY, 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 - TypedPosition p; - first= d.computeIndexInCategory(CONTENT_TYPES_CATEGORY, lastScannedPosition); - while (first < category.length) { - p= (TypedPosition) category[first++]; - d.removePosition(CONTENT_TYPES_CATEGORY, 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(CONTENT_TYPES_CATEGORY, offset); - Position[] category= fDocument.getPositions(CONTENT_TYPES_CATEGORY); - - 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(CONTENT_TYPES_CATEGORY); - - if (category == null || category.length == 0) - return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE); - - int index= fDocument.computeIndexInCategory(CONTENT_TYPES_CATEGORY, 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) { - - List list= new ArrayList(); - - try { - - int endOffset= offset + length; - - Position[] category= fDocument.getPositions(CONTENT_TYPES_CATEGORY); - - 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 (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 (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; - } - - /* - * @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; - } -} 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 5c5233879cf..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java +++ /dev/null @@ -1,202 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.rules; - - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.util.Assert; - - -/** - * 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 { - - protected IRule[] fRules; - protected IToken fDefaultReturnToken; - - protected IDocument fDocument; - protected char[][] fDelimiters; - - protected int fOffset; - protected int fRangeEnd; - - protected int fTokenOffset; - protected int fColumn; - - 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 token 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; - 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; - } - - /** - * Returns the scanner's default return token - * @see #setDefaultReturnToken(IToken) - * - * @return the scanner's default return token - * @since 2.0 - */ - private IToken getDefaultReturnToken() { - return fDefaultReturnToken; - } - - /* - * @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; - } - } - - /* - * @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 9ffdfbcdc6c..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * 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 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) { - super(startSequence, endSequence, token, escapeCharacter, true); - } -}
\ No newline at end of file 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 2c094566bfc..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.java +++ /dev/null @@ -1,120 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.rules; - -import org.eclipse.jface.util.Assert; - - -/** - * Standard implementation of <code>IToken</code>. - */ -public class Token implements IToken { - - private static final int T_UNDEFINED= 0; - private static final int T_EOF= 1; - private static final int T_WHITESPACE= 2; - 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 Undefine, Whitespace, nor End Of File. - * @deprecated will be removed - */ - public static final IToken OTHER= new Token(T_OTHER); - - - private int fType; - 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, whitepsace, or EOF. - * - * @param the 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); - } -}
\ No newline at end of file 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 c4c47050233..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.jface.util.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 - */ - 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; - } - } -}
\ No newline at end of file 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 655925bad96..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordPatternRule.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.jface.util.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; - 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 detected 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 detected 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 b8f8efcde12..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordRule.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.eclipse.jface.text.rules; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jface.util.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 { - - 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(); - - 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 - */ - 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 - */ - 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 - */ - 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 != scanner.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/Annotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java deleted file mode 100644 index 45f7833513a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/Annotation.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.eclipse.jface.text.source; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Canvas; - -/** - * Abstract graphical annotation used in a vertical ruler. - * Annotations are considered being located at layers. The - * vertical ruler paints annotations starting with layer 0 upwards. - * Thus an annotation of layer 5 will be drawn on top of all co-located - * annotations at the layers 4 - 0. Subclasses must provide the annotations paint method. - * - * @see IVerticalRuler - */ -public abstract class Annotation { - - /** The layer of this annotation. */ - private int fLayer; - - /** - * Creates a new annotation. - */ - protected Annotation() { - } - - /** - * Sets the layer of this annotation. - * - * @param layer the layer of this annotation - */ - protected void setLayer(int layer) { - fLayer= layer; - } - - /** - * Convenience method for drawing an image aligned inside a rectangle. - * - * @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 - */ - protected 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: - break; - case SWT.CENTER: - y= (r.height - bounds.height) / 2; - break; - case SWT.BOTTOM: - y= r.height - bounds.height; - break; - } - - gc.drawImage(image, r.x+x, r.y+y); - } - } - - /** - * Convenience method for drawing an image aligned inside a rectangle. - * - * @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 - */ - protected static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int align) { - drawImage(image, gc, canvas, r, align, SWT.CENTER); - } - - /* - * Returns the annotations drawing layer. - * - * @return the annotations drawing layer - */ - public int getLayer() { - return fLayer; - } - - /** - * 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 - */ - public abstract void paint(GC gc, Canvas canvas, Rectangle bounds); -} 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 fc1d1141efa..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java +++ /dev/null @@ -1,107 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - - -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; - -import org.eclipse.jface.text.AbstractHoverInformationControlManager; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IInformationControlCreator; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.util.Assert; - - - -/** - * 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 - */ -class AnnotationBarHoverManager extends AbstractHoverInformationControlManager { - - /** The source viewer the manager is connected to */ - private ISourceViewer fSourceViewer; - /** The vertical ruler the manager is registered with */ - private IVerticalRuler fVerticalRuler; - /** The annotation hover the manager uses to retrieve the information to display */ - private IAnnotationHover fAnnotationHover; - - - /** - * 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 - */ - public AnnotationBarHoverManager(ISourceViewer sourceViewer, IVerticalRuler ruler, IAnnotationHover annotationHover, IInformationControlCreator creator) { - super(creator); - - Assert.isNotNull(sourceViewer); - Assert.isNotNull(annotationHover); - - fSourceViewer= sourceViewer; - fVerticalRuler= ruler; - fAnnotationHover= annotationHover; - - setAnchor(ANCHOR_RIGHT); - setMargins(5, 0); - } - - /* - * @see AbstractHoverInformationControlManager#computeInformation() - */ - protected void computeInformation() { - Point location= getHoverEventLocation(); - int line= fVerticalRuler.toDocumentLineNumber(location.y); - setInformation(fAnnotationHover.getHoverInfo(fSourceViewer, line), computeArea(line)); - } - - /** - * Returns for a given absolute line number the corresponding line - * number relative to the viewer's visible region. - * - * @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 getRelativeLineNumber(int line) throws BadLocationException { - 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= getRelativeLineNumber(line) * lineHeight - text.getTopPixel(); - Point size= fVerticalRuler.getControl().getSize(); - return new Rectangle(0, y, size.x, lineHeight); - } catch (BadLocationException x) { - } - return null; - } -} - 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 9a0f184be2a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationColumn.java +++ /dev/null @@ -1,30 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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/AnnotationModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java deleted file mode 100644 index 3f700737cb4..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModel.java +++ /dev/null @@ -1,324 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.util.Assert; - - -/** - * Standard implementation of <code>IAnnotationModel</code>. This class can directly - * be used by clients. Subclasses may adapt this annotation model to other exsisting - * annotation mechanisms. - */ -public class AnnotationModel implements IAnnotationModel { - - /** The list of managed annotations */ - protected Map fAnnotations; - /** The list of annotation model listeners */ - protected ArrayList fAnnotationModelListeners; - /** The document conntected with this model */ - protected IDocument fDocument; - /** The number of open connections to the same document */ - private int fOpenConnections= 0; - - /** - * Creates a new annotation model. The annotation is empty, i.e. does not - * manage any annotations and is not connected to any document. - */ - public AnnotationModel() { - fAnnotations= Collections.synchronizedMap(new HashMap(10)); - fAnnotationModelListeners= new ArrayList(2); - } - - /* - * @see IAnnotationModel#addAnnotation - */ - public void addAnnotation(Annotation annotation, Position position) { - addAnnotation(annotation, position, true); - } - - /** - * Adds the given annotation to this model. Associates the - * annotation with the given position. If requested, all annotation - * model listeners are informed about this model change. If the annotation - * is already managed by this model nothing happens. - * - * @param annotation the annotation to add - * @param position the associate position - * @param fireModelChange indicates whether to notify all model listeners - */ - protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) { - if (!fAnnotations.containsKey(annotation)) { - - fAnnotations.put(annotation, position); - addPosition(fDocument, position); - - if (fireModelChanged) - fireModelChanged(); - } - } - - /* - * @see IAnnotationModel#addAnnotationModelListener - */ - public void addAnnotationModelListener(IAnnotationModelListener listener) { - if (!fAnnotationModelListeners.contains(listener)) { - fAnnotationModelListeners.add(listener); - listener.modelChanged(this); - } - } - - /** - * Adds the given position to the default position category of the - * given document. - * - * @param document the document to which to add the position - * @param position the position to add - */ - protected void addPosition(IDocument document, Position position) { - if (document != null) { - try { - document.addPosition(position); - } catch (BadLocationException x) { - } - } - } - - /* - * @see IAnnotationModel#connect - */ - public void connect(IDocument document) { - Assert.isTrue(fDocument == null || fDocument == document); - - if (fDocument == null) { - fDocument= document; - Iterator e= fAnnotations.values().iterator(); - while (e.hasNext()) - addPosition(fDocument, (Position) e.next()); - } - - ++ fOpenConnections; - if (fOpenConnections == 1) - connected(); - } - - /** - * Hook method. Is called as soon as this model becomes connected to a document. - */ - protected void connected() { - } - - /** - * Hook method. Is called as soon as this model becomes diconnected from its document. - */ - protected void disconnected() { - } - - /* - * @see IAnnotationModel#disconnect - */ - public void disconnect(IDocument document) { - - Assert.isTrue(fDocument == document); - - -- fOpenConnections; - if (fOpenConnections == 0) { - - disconnected(); - - if (fDocument != null) { - Iterator e= fAnnotations.values().iterator(); - while (e.hasNext()) { - Position p= (Position) e.next(); - fDocument.removePosition(p); - } - fDocument= null; - } - } - } - - /** - * Informs all annotation model listeners that this model has been changed. - */ - protected void fireModelChanged() { - fireModelChanged(new AnnotationModelEvent(this)); - } - - /** - * Informs all annotation model listeners that this model has been changed - * as described in the annotation model event. The event is sent out - * to all listeners implementing <code>IAnnotationModelListenerExtension</code>. - * All other listeners are notified by just calling <code>modelChanged(IAnnotationModel)</code>. - * - * @param event the event to be sent out to the listeners - * @since 2.0 - */ - protected void fireModelChanged(AnnotationModelEvent event) { - ArrayList v= new ArrayList(fAnnotationModelListeners); - Iterator e= v.iterator(); - while (e.hasNext()) { - IAnnotationModelListener l= (IAnnotationModelListener) e.next(); - if (l instanceof IAnnotationModelListenerExtension) - ((IAnnotationModelListenerExtension) l).modelChanged(event); - else - l.modelChanged(this); - } - } - - /** - * Removes the given annotations from this model. If requested all - * annotation model listeners will be informed about this change. - * <code>modelInitiated</code> indicates whether the deletion has - * been initiated by this model or by one of its clients. - * - * @param annotations the annotations to be removed - * @param fireModelChanged indicates whether to notify all model listeners - * @param modelInitiated indicates whether this changes has been initiated by this model - */ - protected void removeAnnotations(List annotations, boolean fireModelChanged, boolean modelInitiated) { - if (annotations.size() > 0) { - Iterator e= annotations.iterator(); - while (e.hasNext()) - removeAnnotation((Annotation) e.next(), false); - - if (fireModelChanged) - fireModelChanged(); - } - } - - /** - * Removes all annotations from the model whose associated positions have been - * deleted. If requested inform all model listeners about the change. - * - * @param fireModelChanged indicates whether to notify all model listeners - */ - protected void cleanup(boolean fireModelChanged) { - ArrayList deleted= new ArrayList(); - Iterator e= fAnnotations.keySet().iterator(); - while (e.hasNext()) { - Annotation a= (Annotation) e.next(); - Position p= (Position) fAnnotations.get(a); - if (p == null || p.isDeleted()) - deleted.add(a); - } - - removeAnnotations(deleted, fireModelChanged, false); - } - - /* - * @see IAnnotationModel#getAnnotationsIterator - */ - public Iterator getAnnotationIterator() { - return getAnnotationIterator(true); - } - - /** - * Returns all annotations managed by this model. <code>cleanup</code> - * indicates whether all annotations whose associated positions are - * deleted should previously be removed from the model. - * - * @param cleanup indicates whether annotations with deleted associated positions are removed - * @return all annotations managed by this model - */ - protected Iterator getAnnotationIterator(boolean cleanup) { - if (cleanup) - cleanup(false); - - synchronized (fAnnotations) { - return new ArrayList(fAnnotations.keySet()).iterator(); - } - } - - /* - * @see IAnnotationModel#getPosition - */ - public Position getPosition(Annotation annotation) { - return (Position) fAnnotations.get(annotation); - } - - /** - * Removes all annotations from the annotation model and - * informs all model listeners about this change. - */ - public void removeAllAnnotations() { - removeAllAnnotations(true); - } - - /** - * Removes all annotations from the annotation model. If requested - * inform all model change listeners about this change. - * - * @param fireModelChanged indicates whether to notify all model listeners - */ - protected void removeAllAnnotations(boolean fireModelChanged) { - - if (fDocument != null) { - Iterator e= fAnnotations.values().iterator(); - while (e.hasNext()) { - Position p= (Position) e.next(); - fDocument.removePosition(p); - } - } - - fAnnotations.clear(); - - if (fireModelChanged) - fireModelChanged(); - } - - /* - * @see IAnnotationModel#removeAnnotation - */ - public void removeAnnotation(Annotation annotation) { - removeAnnotation(annotation, true); - } - - /** - * Removes the given annotation from the annotation model. - * If requested inform all model change listeners about this change. - * - * @param annotation the annotation to be removed - * @param fireModelChanged indicates whether to notify all model listeners - */ - protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) { - if (fAnnotations.containsKey(annotation)) { - - if (fDocument != null) { - Position p= (Position) fAnnotations.get(annotation); - fDocument.removePosition(p); - } - - fAnnotations.remove(annotation); - - if (fireModelChanged) - fireModelChanged(); - } - } - - /* - * @see IAnnotationModel#removeAnnotationModelListener - */ - public void removeAnnotationModelListener(IAnnotationModelListener listener) { - fAnnotationModelListeners.remove(listener); - } -} diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java deleted file mode 100644 index 46e6cf4c4d5..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java +++ /dev/null @@ -1,44 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - -/** - * Specification of changes applied to annotation models. - * The event carries the changed annotation model. <p> - * Work in progress. Intented to also contain added, removed, and modified annotations. - * - * @see IAnnotationModel - * @since 2.0 - */ -public class AnnotationModelEvent { - - /** The model this event refers to. For internal use only. */ - IAnnotationModel fAnnotationModel; - - /** - * Creates a new annotation model event for the given model. - * - * @param model the model - */ - public AnnotationModelEvent(IAnnotationModel model) { - fAnnotationModel= model; - } - - /** - * Returns the model this event refers to. - * - * @return the model this events belongs to - */ - public IAnnotationModel getAnnotationModel() { - return fAnnotationModel; - } -} 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 3387d439319..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java +++ /dev/null @@ -1,383 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.IViewportListener; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextEvent; - - -/** - * A vertical ruler column showing graphical representations of annotations. - * Will become final. Do not subclass. - * @since 2.0 - */ -public class AnnotationRulerColumn implements IVerticalRulerColumn { - - /** - * Internal listener class. - */ - class InternalListener implements IViewportListener, IAnnotationModelListener, ITextListener { - - /* - * @see IViewportListener#viewportChanged - */ - public void viewportChanged(int verticalPosition) { - if (verticalPosition != fScrollPos) - redraw(); - } - - /* - * @see IAnnotationModelListener#modelChanged - */ - public void modelChanged(IAnnotationModel model) { - postRedraw(); - } - - /* - * @see ITextListener#textChanged - */ - public void textChanged(TextEvent e) { - if (e.getViewerRedrawState()) - redraw(); - } - }; - - - /** 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; - - - /** - * 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(); - - fCanvas= new Canvas(parentControl, SWT.NO_BACKGROUND); - - 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 MouseListener() { - public void mouseUp(MouseEvent event) { - } - - public void mouseDown(MouseEvent event) { - fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); - } - - public void mouseDoubleClick(MouseEvent event) { - fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); - } - }); - - if (fCachedTextViewer != null) { - fCachedTextViewer.addViewportListener(fInternalListener); - fCachedTextViewer.addTextListener(fInternalListener); - } - - return fCanvas; - } - - /** - * 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; - } - } - - /** - * 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); - 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 document offset of the upper left corner including partially visible lines - */ - private int getInclusiveTopIndexStartOffset() { - - if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed()) { - int top= fCachedTextViewer.getTopIndex(); - if ((fCachedTextWidget.getTopPixel() % fCachedTextWidget.getLineHeight()) != 0) - top--; - try { - IDocument document= fCachedTextViewer.getDocument(); - return document.getLineOffset(top); - } catch (BadLocationException ex) { - } - } - - return -1; - } - - /** - * Draws the vertical ruler w/o drawing the Canvas background. - * - * @param gc the gc to draw into - */ - private void doPaint(GC gc) { - - if (fModel == null || fCachedTextViewer == null) - return; - - int topLeft= getInclusiveTopIndexStartOffset(); - int bottomRight= fCachedTextViewer.getBottomIndexEndOffset(); - // http://dev.eclipse.org/bugs/show_bug.cgi?id=14938 - int viewPort= bottomRight + 1 - 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 thru layers. - - for (int layer= 0; layer < maxLayer; layer++) { - Iterator iter= fModel.getAnnotationIterator(); - while (iter.hasNext()) { - Annotation annotation= (Annotation) iter.next(); - - int lay= annotation.getLayer(); - 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; - startLine -= topLine; - - int endLine= startLine; - if (length > 0) - endLine= doc.getLineOfOffset(offset + length - 1); - if (endLine > bottomLine) - endLine= bottomLine; - 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) // annotation within visible area - annotation.paint(gc, fCanvas, r); - - } catch (BadLocationException e) { - } - } - } - } - - /** - * Post a redraw request for thid 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 (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) { - } -} 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 ed75a073e00..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/CompositeRuler.java +++ /dev/null @@ -1,714 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - - -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.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.MouseAdapter; -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.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.Layout; -import org.eclipse.swt.widgets.Menu; - -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; - - -/** - * 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. - * Clients may instantiate and configure this class. - * - * @see IVerticalRulerColumn - * @see ITextViewer - * @since 2.0 - */ -public final class CompositeRuler implements IVerticalRuler, IVerticalRulerExtension { - - - /** - * 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); - } - 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; - } - } - }; - - /** - * 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 mouse listener for opening the context menu. */ - private MouseListener fMouseListener; - - /** - * 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); - fMouseListener= new MouseAdapter() { - public void mouseUp(MouseEvent e) { - if (3 == e.button) { - Menu menu= getMenu(); - if (menu != null) { - Control c= (Control) e.widget; - Point p= new Point(e.x, e.y); - Point p2= c.toDisplay(p); - menu.setLocation(p2.x, p2.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 listner 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.addMouseListener(fMouseListener); - } - } - - /** - * 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.removeMouseListener(fMouseListener); - } - } - - /* - * @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; - - - /** - * Constructs a new composite vertical ruler. - */ - public CompositeRuler() { - } - - /** - * 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) { - 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 column= (IVerticalRulerColumn) fDecorators.get(index); - fDecorators.remove(index); - Control cc= column.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 e= fDecorators.iterator(); - while (e.hasNext()) { - IVerticalRulerColumn column= (IVerticalRulerColumn) e.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(); - } - return width; - } - - /* - * @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()); - try { - IRegion r= fTextViewer.getVisibleRegion(); - IDocument d= fTextViewer.getDocument(); - line += d.getLineOfOffset(r.getOffset()); - } catch (BadLocationException x) { - } - - return line; - } - - /** - * 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; - } -} 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 53a9160e672..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHover.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.eclipse.jface.text.source; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -/** - * 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); -}
\ No newline at end of file diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModel.java deleted file mode 100644 index 7c03cc7121b..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModel.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.eclipse.jface.text.source; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.Iterator; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - - -/** - * This interface defines the model component for a vertical ruler. - * It maintains a set of annotations and notifies registered annotation - * model listeners about annotation model changes. It also provides methods - * for inquerying the current offset and length of an annotation managed - * by this model.<p> - * Clients may implement this interface or use the default implementation provided - * by <code>AnnotationModel</code>. - * - * @see IVerticalRuler - * @see Annotation - * @see IAnnotationModelListener - */ -public interface IAnnotationModel { - - /** - * Registers the annotation model listener with this annotation model. - * After registration listener is informed about each change of this model. - * If the listener is already registered nothing happens. - * - * @param listener the listener to be registered, may not be <code>null</code> - */ - void addAnnotationModelListener(IAnnotationModelListener listener); - - /** - * Removes the listener from the model's list of annotation model listeners. - * If the listener is not registered with the model nothing happens. - * - * @param listener the listener to be removed, may not be <code>null</code> - */ - void removeAnnotationModelListener(IAnnotationModelListener listener); - - /** - * Connects the annotation model to a document. The annotations managed - * by this model must subsequently update according to the changes applied - * to the document. Once an annotation model is connected to a document, - * all further <code>connect</code> calls must mention the document the - * model is already connected to. An annotation model primarily uses - * <code>connect</code> and <code>disconnect</code> for reference counting - * the document. Reference counting frees the clients from keeping tracker - * whether a model has already been connected to a document. - * - * @param document the document the model gets connected to, - * may not be <code>null</code> - * - * @see #disconnect - */ - void connect(IDocument document); - - /** - * Disconnects this model from a document. After that, document changes no longer matter. - * An annotation model may only be disconnected from a document to which it has been - * connected before. If the model reference counts the connections to a document, - * the connection to the document may only be terminated if the reference count does - * down to 0. - * - * @param document the document the model gets disconnected from, - * may not be <code>null</code> - * - * @see #connect for further specification details - */ - void disconnect(IDocument document); - - /** - * Adds a annotation to this annotation model. The annotation is associated with - * with the given position which desscribes the range covered by the annotation. - * All registered annotation model listeners are informed about the change. - * If the model is connected to a document, the position is automatically - * updated on document changes. If the annotation is already managed by - * this annotation model nothing happens. - * - * @param annotation the annotation to add, may not be <code>null</code> - * @param position the position describing the range covered by this annotation, - * may not be <code>null</code> - */ - void addAnnotation(Annotation annotation, Position position); - - /** - * Removes the given annotation from the model. I.e. the annotation is no - * longer managed by this model. The position associated with the annotation - * is no longer updated on document changes. If the annotation is not - * managed by this model, nothing happens. - * - * @param annotation the annotation to be removed from this model, - * may not be <code>null</code> - */ - void removeAnnotation(Annotation annotation); - - /** - * Returns all annotations managed by this model. - * - * @return all annotations managed by this model - */ - Iterator getAnnotationIterator(); - - /** - * Returns the position associated with the given annotation. - * - * @param annotation the annotation whose position should be returned - * @return the position of the given annotation or <code>null</code> if no - * associated annotation exists - */ - Position getPosition(Annotation annotation); -} - diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java deleted file mode 100644 index 20cdd88f834..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.eclipse.jface.text.source; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Interface for objects interested in getting informed about - * annotation model changes. Changes are the addition or removal - * of annotations managed by the model. Clients may implement - * this interface. - * - * @see IAnnotationModel - */ -public interface IAnnotationModelListener { - - /** - * Called if a model change occurred on the given model. - * - * @param model the changed annotation model - */ - void modelChanged(IAnnotationModel model); -} diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java deleted file mode 100644 index b3076c9b25a..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationModelListenerExtension.java +++ /dev/null @@ -1,30 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - -/** - * Extension interface for <code>IAnnotationModelListener</code>. Introduces a - * notification mechanism that notifies the userby means of <code>AnnotationModelEvent</code>s. - * Thus, more detailed information can be sent to the listener. Will replace the original notification - * mechanism of <code>IAnnotationModelListener</code>. - * - * @since 2.0 - */ -public interface IAnnotationModelListenerExtension { - - /** - * Called if a model change occurred on the given model. - * - * @param event the event to be sent out - */ - void modelChanged(AnnotationModelEvent event); -} 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 ad582c530a6..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewer.java +++ /dev/null @@ -1,162 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 completetion - * 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. - * - * @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 approriate - * <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 made visible. An approriate - * <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 visibleRegionOffset the offset of the visible region - * @param visibleRegionLength the length of the visible region - * - * @see ITextViewer#setDocument(IDocument, int, int) - */ - void setDocument(IDocument document, IAnnotationModel annotationModel, int visibleRegionOffset, int visibleRegionLength); - - /** - * 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. - * - * @return the viewer's range indication - */ - 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); -}
\ No newline at end of file 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 4844c7e8efa..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRuler.java +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 a line oriented annotation presentation - * area. 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>VerticalRuler</code>. - * - * @see ITextViewer - * @see IVerticalRulerInfo - */ -public interface IVerticalRuler extends IVerticalRulerInfo { - - /** - * Associates an annotation model with this ruler. - * If the ruler is visible it must display those annotions - * of the annotation model whose visual representation overlaps - * with the viewport of the rulers source viewer. - * 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 e5ec6c3318e..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerColumn.java +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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 full 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 25e4121a8b0..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerExtension.java +++ /dev/null @@ -1,39 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - - -import org.eclipse.swt.graphics.Font; - - -/** - * Extension interface for <code>IVerticalRuler</code>. - * @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, e.g., 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 1fe666daff4..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfo.java +++ /dev/null @@ -1,60 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v0.5 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v05.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 a line oriented annotation presentation - * area. The 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. - * - * @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 - */ - 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/JFaceTextMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java deleted file mode 100644 index 96f5fc4621c..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java +++ /dev/null @@ -1,49 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - -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$ - } - } -}
\ No newline at end of file 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 ceba38b3ad9..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java +++ /dev/null @@ -1,465 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - - -import java.text.NumberFormat; - -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.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.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.IViewportListener; -import org.eclipse.jface.text.TextEvent; - - -/** - * A vertical ruler column displaying line numbers. - * Clients may use this class as is. - * @since 2.0 - */ -public final 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 (!event.getViewerRedrawState()) - return; - - if (computeNumberOfDigits()) { - computeIndentations(); - layout(); - return; - } - - if (fSensitiveToTextChanges || event.getDocumentEvent() == null) { - if (fCanvas != null && !fCanvas.isDisposed()) { - Display d= fCanvas.getDisplay(); - if (d != null) { - d.asyncExec(new Runnable() { - public void run() { - redraw(); - } - }); - } - } - } - } - }; - - /** 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; - - - /** - * 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; - } - - /** - * 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 the number of digits to be displayed - */ - protected boolean computeNumberOfDigits() { - - IDocument document= fCachedTextViewer.getDocument(); - int lines= document == null ? 0 : document.getNumberOfLines(); - - int digits= 2; - while (lines > Math.pow(10, digits) -1) { - ++digits; - } - - if (fCachedNumberOfDigits != digits) { - fCachedNumberOfDigits= digits; - return true; - } - - return false; - } - - /** - * Layouts the enclosing viewer to adapt the layout to changes of the - * size of the individual components. - */ - protected void layout() { - 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() { - GC gc= new GC(fCanvas); - try { - - gc.setFont(fCanvas.getFont()); - NumberFormat nf= NumberFormat.getInstance(); - - fIndentation= new int[fCachedNumberOfDigits + 1]; - - double number= Math.pow(10, fCachedNumberOfDigits) - 1; - Point p= gc.stringExtent(nf.format(number)); - fIndentation[0]= p.x; - - for (int i= 1; i <= fCachedNumberOfDigits; i++) { - number= Math.pow(10, i) - 1; - p= gc.stringExtent(nf.format(number)); - 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 MouseListener() { - public void mouseUp(MouseEvent event) { - } - - public void mouseDown(MouseEvent event) { - fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); - selectLine(fParentRuler.getLineOfLastMouseButtonActivity()); - } - - public void mouseDoubleClick(MouseEvent event) { - fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); - } - }); - - 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); - - computeNumberOfDigits(); - computeIndentations(); - return fCanvas; - } - - /** - * Selects the given line in the text viewer. - * - * @param line the number of the line to be selected - */ - private void selectLine(int line) { - try { - IDocument document= fCachedTextViewer.getDocument(); - int offset= document.getLineOffset(fParentRuler.getLineOfLastMouseButtonActivity()); - fCachedTextViewer.setSelectedRange(offset, 0); - } catch (BadLocationException x) { - } - } - - /** - * Disposes the column's resources. - */ - private 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); - 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; - - - int firstLine= 0; - - int topLine= fCachedTextViewer.getTopIndex() -1; - int bottomLine= fCachedTextViewer.getBottomIndex() + 1; - - try { - - IRegion region= fCachedTextViewer.getVisibleRegion(); - IDocument doc= fCachedTextViewer.getDocument(); - - 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; - - NumberFormat nf= NumberFormat.getInstance(); - int y= ((topLine - firstLine) * lineheight) - fScrollPos + fCachedTextViewer.getTopInset(); - for (int line= topLine; line <= bottomLine; line++, y+= lineheight) { - - if (y >= canvasheight) - break; - - String s= Integer.toString(line + 1); - int indentation= fIndentation[s.length()]; - gc.drawString(nf.format(line + 1), indentation, y); - } - } - - /* - * @see IVerticalRulerColumn#redraw - */ - public void redraw() { - 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); - computeNumberOfDigits(); - computeIndentations(); - } - } -} 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 15dcb2d68bc..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java +++ /dev/null @@ -1,519 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text.source; - - -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.IDocument; -import org.eclipse.jface.text.IRegion; -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.IContentFormatter; -import org.eclipse.jface.text.information.IInformationPresenter; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -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.<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 { - - - /** - * Layout of a source viewer. Vertical ruler and text widget are shown side by side. - */ - 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 - */ - protected 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 rulerWidth= fVerticalRuler.getWidth(); - fVerticalRuler.getControl().setBounds(0, 0, rulerWidth, clArea.height - scrollbarHeight); - getTextWidget().setBounds(rulerWidth + fGap, 0, clArea.width - rulerWidth - fGap, clArea.height); - - } else - getTextWidget().setBounds(0, 0, clArea.width, clArea.height); - } - }; - - - /** 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; - /** - * 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 VisualAnnotationModel 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 size of the gap between the vertical ruler and the text widget */ - protected final static int GAP_SIZE= 2; - - /** - * 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) { - super(); - - fVerticalRuler= ruler; - fIsVerticalRulerVisible= (ruler != null); - createControl(parent, styles); - } - - /* - * @see TextViewer#createControl - */ - protected void createControl(Composite parent, int styles) { - - if (fVerticalRuler != null) { - styles= (styles & ~SWT.BORDER); - fComposite= new Canvas(parent, SWT.NONE); - fComposite.setLayout(new RulerLayout(GAP_SIZE)); - parent= fComposite; - } - - super.createControl(parent, styles); - - if (fComposite != null) - fVerticalRuler.createControl(fComposite, this); - } - - /* - * @see TextViewer#getControl - */ - public Control getControl() { - if (fComposite != null) - return fComposite; - return super.getControl(); - } - - /* - * @see ISourceViewer#setAnnotationHover - */ - public void setAnnotationHover(IAnnotationHover annotationHover) { - fAnnotationHover= annotationHover; - } - - /* - * @see ISourceViewer#configure - */ - public void configure(SourceViewerConfiguration configuration) { - - if (getTextWidget() == null) - return; - - // install content type independent plugins - 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)); - - setHoverControlCreator(configuration.getInformationControlCreator(this)); - - // install content type specific plugins - 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); - setTextHover(configuration.getTextHover(this, t), t); - - 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(); - } - - /* - * @see TextViewer#activatePlugins - */ - public void activatePlugins() { - - if (fVerticalRuler != null && fAnnotationHover != null && fVerticalRulerHoveringController == null) { - fVerticalRulerHoveringController= new AnnotationBarHoverManager(this, fVerticalRuler, fAnnotationHover, fHoverControlCreator); - fVerticalRulerHoveringController.install(fVerticalRuler.getControl()); - } - - 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); - } - - /* - * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int) - */ - public void setDocument(IDocument document, IAnnotationModel annotationModel, int visibleRegionOffset, int visibleRegionLength) { - - if (fVerticalRuler == null) { - - if (visibleRegionOffset == -1 && visibleRegionLength == -1) - super.setDocument(document); - else - super.setDocument(document, visibleRegionOffset, visibleRegionLength); - - } else { - - if (fVisualAnnotationModel != null && getDocument() != null) - fVisualAnnotationModel.disconnect(getDocument()); - - if (visibleRegionOffset == -1 && visibleRegionLength == -1) - super.setDocument(document); - else - super.setDocument(document, visibleRegionOffset, visibleRegionLength); - - if (annotationModel != null && document != null) { - fVisualAnnotationModel= new VisualAnnotationModel(annotationModel); - fVisualAnnotationModel.connect(document); - } else { - fVisualAnnotationModel= null; - } - - fVerticalRuler.setModel(fVisualAnnotationModel); - } - } - - /* - * @see ISourceViewer#getAnnotationModel - */ - public IAnnotationModel getAnnotationModel() { - if (fVisualAnnotationModel != null) - return fVisualAnnotationModel.getModelAnnotationModel(); - return null; - } - - /* - * @see TextViewer#handleDispose - */ - protected void handleDispose() { - - 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; - } - - if (fVisualAnnotationModel != null && getDocument() != null) { - fVisualAnnotationModel.disconnect(getDocument()); - fVisualAnnotationModel= null; - } - - fVerticalRuler= null; - - if (fVerticalRulerHoveringController != null) { - fVerticalRulerHoveringController.dispose(); - fVerticalRulerHoveringController= null; - } - - // http://dev.eclipse.org/bugs/show_bug.cgi?id=15300 - fComposite= null; - - super.handleDispose(); - } - - /* - * @see ITextOperationTarget#canDoOperation - */ - public boolean canDoOperation(int operation) { - - if (getTextWidget() == null || !redraws()) - 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) { - Point p= getSelectedRange(); - int length= (p == null ? -1 : p.y); - return (fContentFormatter != null && isEditable() && (length == 0 || isBlockSelected())); - } - - return super.canDoOperation(operation); - } - - /* - * @see ITextOperationTarget#doOperation - */ - public void doOperation(int operation) { - - if (getTextWidget() == null || !redraws()) - return; - - switch (operation) { - case CONTENTASSIST_PROPOSALS: - fContentAssistant.showPossibleCompletions(); - return; - case CONTENTASSIST_CONTEXT_INFORMATION: - fContentAssistant.showContextInformation(); - return; - case INFORMATION: - fInformationPresenter.showInformation(); - return; - case FORMAT: { - Point s= getSelectedRange(); - IDocument document= getDocument(); - - Position p= new Position(s.x, s.y); - IRegion r= (s.y == 0) ? getVisibleRegion() : new Region(s.x, s.y); - - try { - setRedraw(false); - document.addPosition(p); - fContentFormatter.format(document, r); - - setSelectedRange(p.getOffset(), p.getLength()); - - } catch (BadLocationException e) { - // should not happen - } finally { - setRedraw(true); - document.removePosition(p); - } - - return; - } - default: - super.doOperation(operation); - } - } - - /* - * @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 - */ - public void setRangeIndicator(Annotation rangeIndicator) { - fRangeIndicator= rangeIndicator; - } - - /* - * @see ISourceViewer#setRangeIndication - */ - public void setRangeIndication(int start, int length, boolean moveCursor) { - - if (moveCursor) { - setSelectedRange(start, 0); - revealRange(start, length); - } - - if (fRangeIndicator != null && fVisualAnnotationModel != null) - fVisualAnnotationModel.modifyAnnotation(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.modifyAnnotation(fRangeIndicator, null); - } - - /* - * @see ISourceViewer#showAnnotations(boolean) - */ - public void showAnnotations(boolean show) { - boolean old= fIsVerticalRulerVisible; - fIsVerticalRulerVisible= (show && fVerticalRuler != null); - if (old != fIsVerticalRulerVisible) { - // http://dev.eclipse.org/bugs/show_bug.cgi?id=15300 - if (fComposite != null && !fComposite.isDisposed()) - fComposite.layout(); - } - } -}
\ No newline at end of file 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 2e5e46836fe..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java +++ /dev/null @@ -1,245 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 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.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.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 knowlegde 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>. - * - * @return the presentation reconciler or <code>null</code> if presentation reconciling should not be supported - */ - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - return null; - } - - /** - * 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 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 }; - } -} 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 707da51d8ad..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java +++ /dev/null @@ -1,446 +0,0 @@ -package org.eclipse.jface.text.source; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -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.IViewportListener; -import org.eclipse.jface.text.Position; -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; - - - /** - * Constructs a vertical ruler with the given width. - * - * @param width the width of the vertical ruler - */ - public VerticalRuler(int width) { - fWidth= width; - } - - /* - * @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); - try { - gc.setBackground(fCanvas.getBackground()); - gc.fillRectangle(0, 0, size.x, size.y); - 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= fTextViewer.getTopIndex(); - if ((textWidget.getTopPixel() % textWidget.getLineHeight()) != 0) - top--; - try { - IDocument document= fTextViewer.getDocument(); - return document.getLineOffset(top); - } catch (BadLocationException ex) { - } - } - - return -1; - } - - /** - * Draws the vertical ruler w/o drawing the Canvas background. - * - * @param gc the gc to draw into - */ - private void doPaint(GC gc) { - - if (fModel == null || fTextViewer == null) - return; - - 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 thru layers. - - for (int layer= 0; layer < maxLayer; layer++) { - Iterator iter= fModel.getAnnotationIterator(); - while (iter.hasNext()) { - Annotation annotation= (Annotation) iter.next(); - - int lay= annotation.getLayer(); - 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; - startLine -= topLine; - - int endLine= startLine; - if (length > 0) - endLine= doc.getLineOfOffset(offset + length - 1); - if (endLine > bottomLine) - endLine= bottomLine; - 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) // annotation within visible area - annotation.paint(gc, fCanvas, r); - - } catch (BadLocationException e) { - } - } - } - } - - /** - * 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()); - try { - IRegion r= fTextViewer.getVisibleRegion(); - IDocument d= fTextViewer.getDocument(); - line += d.getLineOfOffset(r.getOffset()); - } catch (BadLocationException x) { - } - - return line; - } - - /* - * @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); - } - - /** - * @deprecated will be removed - * @since 2.0 - */ - public void addMouseListener(MouseListener listener) { - if (fCanvas != null && !fCanvas.isDisposed()) - fCanvas.addMouseListener(listener); - } - - /** - * @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/VisualAnnotationModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java deleted file mode 100644 index d24a4d358ec..00000000000 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.eclipse.jface.text.source; - - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -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 - */ - public void addAnnotationModelListener(IAnnotationModelListener listener) { - - if (fModel != null && fAnnotationModelListeners.isEmpty()) - fModel.addAnnotationModelListener(this); - - super.addAnnotationModelListener(listener); - } - - /* - * @see IAnnotationModel#connect - */ - public void connect(IDocument document) { - super.connect(document); - if (fModel != null) - fModel.connect(document); - } - - /* - * @see IAnnotationModel#disconnect - */ - 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 - */ - public Position getPosition(Annotation annotation) { - - Position p= (Position) fAnnotations.get(annotation); - if (p != null) - return p; - - if (fModel != null) - return fModel.getPosition(annotation); - - return null; - } - - /* - * @see IAnnotationModelListener#modelChanged - */ - public void modelChanged(IAnnotationModel model) { - if (model == fModel) { - int size= fAnnotationModelListeners.size(); - for (int i= 0; i < size; i++) { - IAnnotationModelListener l= (IAnnotationModelListener) fAnnotationModelListeners.get(i); - l.modelChanged(this); - } - } - } - - - /** - * Modifies associated position of the given annotation to the given position. - * If the annotation is not yet managed by this annotation model, the annotation - * is added. All annotation model change listeners will be informed about the change. - * - * @param annotation the annotation whose associated position should be modified - * @param position the position to whose values the associated position should be changed - */ - public void modifyAnnotation(Annotation annotation, Position position) { - modifyAnnotation(annotation, position, true); - } - - /** - * Modifies the associated position of the given annotation to the given position. - * If the annotation is not yet managed by this annotation model, the annotation - * is added. If requested, all annotation model change listeners will be informed - * about the change. - * - * @param annotation the annotation whose associated position should be modified - * @param position the position to whose values the associated position should be changed - * @param fireModelChanged indicates whether to notify all model listeners - */ - private void modifyAnnotation(Annotation annotation, Position position, boolean fireModelChanged) { - if (position == null) { - removeAnnotation(annotation, fireModelChanged); - } else { - Position p= (Position) fAnnotations.get(annotation); - if (p != null) { - p.setOffset(position.getOffset()); - p.setLength(position.getLength()); - if (fireModelChanged) - fireModelChanged(); - } else { - addAnnotation(annotation, position, fireModelChanged); - } - } - } - - /* - * @see IAnnotationModel#removeAnnotationModelListener - */ - 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> - <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. -This package also provides default implementations for all defined interfaces. -<br> -</body> -</html> diff --git a/org.eclipse.search/.classpath b/org.eclipse.search/.classpath deleted file mode 100644 index 15ba3b97b19..00000000000 --- a/org.eclipse.search/.classpath +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="search"/> - <classpathentry kind="src" path="/org.eclipse.core.boot"/> - <classpathentry kind="src" path="/org.eclipse.core.runtime"/> - <classpathentry kind="src" path="/org.apache.xerces"/> - <classpathentry kind="src" path="/org.eclipse.core.resources"/> - <classpathentry kind="src" path="/org.eclipse.ui"/> - <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/org.eclipse.search/.cvsignore b/org.eclipse.search/.cvsignore deleted file mode 100644 index ba077a4031a..00000000000 --- a/org.eclipse.search/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/org.eclipse.search/.project b/org.eclipse.search/.project deleted file mode 100644 index 11a440394c3..00000000000 --- a/org.eclipse.search/.project +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.search</name> - <comment></comment> - <projects> - <project>org.apache.xerces</project> - <project>org.eclipse.core.boot</project> - <project>org.eclipse.core.resources</project> - <project>org.eclipse.core.runtime</project> - <project>org.eclipse.swt</project> - <project>org.eclipse.ui</project> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/org.eclipse.search/about.html b/org.eclipse.search/about.html deleted file mode 100644 index 9db411aab99..00000000000 --- a/org.eclipse.search/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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the -Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or -other code and/or documentation ("Modifications") 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.search/build.properties b/org.eclipse.search/build.properties deleted file mode 100644 index 03f726f70a0..00000000000 --- a/org.eclipse.search/build.properties +++ /dev/null @@ -1,7 +0,0 @@ -bin.includes = plugin.xml,\ - about.html,\ - icons/,\ - plugin.properties,\ - *.jar -source.search.jar = search/ -src.includes=about.html diff --git a/org.eclipse.search/buildnotes_search.html b/org.eclipse.search/buildnotes_search.html deleted file mode 100644 index 5a60ad1a6d5..00000000000 --- a/org.eclipse.search/buildnotes_search.html +++ /dev/null @@ -1,519 +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="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]"> - - - - <meta name="Author" content="IBM"><title>Eclipse Platform Release Notes - Search</title></head><body> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020919 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - - - - - - - -<ul> -<li>Added "openWith" context menu<br></li> -</ul> - - - - - - - -<h2>Problem Reports</h2> - - - - - - - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F09%2F10&chfieldto=2002%2F09%2F20&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/09/10 and 2002/09/19.<br> -<br> -<br> - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020910 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - - - - - - -<ul> -<li><br></li> -</ul> - - - - - - -<h2>Problem Reports</h2> - - - - - - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F09%2F03&chfieldto=2002%2F09%2F10&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/09/03 and 2002/09/10.<br> -<br> - -<br> - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020903 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - - - - - -<ul> -<li><br></li> -</ul> - - - - - -<h2>Problem Reports</h2> - - - - - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F08%2F27&chfieldto=2002%2F09%2F03&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/08/27 and 2002/09/03.<br> -<br> - -<br> - - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020827 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - - - - -<ul> -<li><br></li> -</ul> - - - - -<h2>Problem Reports</h2> - - - - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F08%2F20&chfieldto=2002%2F08%2F27&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/08/20 and 2002/08/27.<br> - -<br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020820 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - - - -<ul> -<li>Search view supports select all<br></li> -</ul> - - - -<h2>Problem Reports</h2> - - - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F08%2F13&chfieldto=2002%2F08%2F20&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/08/13 and 2002/08/20.<br> - -<br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020813 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - - -<ul> -<li><br></li> -</ul> - - -<h2>Problem Reports</h2> - - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F07%2F23&chfieldto=2002%2F08%2F13&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/07/23 and 2002/08/13.<br> - -<br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020723 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> - -<ul> - -<li>Removed all 2.0 build notes. They can be found in <a href="buildnotes_search_2_0.html">buildnotes_search_2_0.html</a><br></li> -</ul> - -<h2>Problem Reports</h2> - -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F06%2F29&chfieldto=2002%2F07%2F23&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> to see BRs which have been marked as RESOLVED or CLOSED between 2002/06/29 and 2002/07/23.<br> - -<br> - -<br> - -<a href="doc/hglegal2002.htm"><img src="doc/ngibmcpy2002.gif" border="0" height="14" width="324" alt="Copyright IBM Corporation and others 2000, 2002."></a> -<br> - -<br> - -<br> - -<br> - -<br> -<br> -<br> -<br> -<br> -<br> -</body></html>
\ No newline at end of file diff --git a/org.eclipse.search/doc/hglegal.htm b/org.eclipse.search/doc/hglegal.htm deleted file mode 100644 index c59811321a9..00000000000 --- a/org.eclipse.search/doc/hglegal.htm +++ /dev/null @@ -1,14 +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="GENERATOR" content="Mozilla/4.73 [en] (Win98; U) [Netscape]"> - <title>Legal Notices</title> -</head> -<body> - -<h3> -<a NAME="Notices"></a>Notices</h3> -(c) Copyright IBM Corp. 2000, 2001. All Rights Reserved. -</body> -</html> diff --git a/org.eclipse.search/doc/hglegal2002.htm b/org.eclipse.search/doc/hglegal2002.htm deleted file mode 100644 index bd5106e8a36..00000000000 --- a/org.eclipse.search/doc/hglegal2002.htm +++ /dev/null @@ -1,14 +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"> - <LINK REL="STYLESHEET" HREF="book.css" CHARSET="ISO-8859-1" TYPE="text/css"> - <title>Legal Notices</title> -</head> -<body> - -<h3> -<a NAME="Notices"></a>Notices</h3> -(c) Copyright IBM Corp. 2000, 2002. All Rights Reserved. -</body> -</html> diff --git a/org.eclipse.search/doc/ngibmcpy.gif b/org.eclipse.search/doc/ngibmcpy.gif Binary files differdeleted file mode 100644 index 360f8e99891..00000000000 --- a/org.eclipse.search/doc/ngibmcpy.gif +++ /dev/null diff --git a/org.eclipse.search/doc/ngibmcpy2002.gif b/org.eclipse.search/doc/ngibmcpy2002.gif Binary files differdeleted file mode 100644 index 61cef485216..00000000000 --- a/org.eclipse.search/doc/ngibmcpy2002.gif +++ /dev/null diff --git a/org.eclipse.search/doc/org_eclipse_search.html b/org.eclipse.search/doc/org_eclipse_search.html deleted file mode 100644 index a079e8dfc13..00000000000 --- a/org.eclipse.search/doc/org_eclipse_search.html +++ /dev/null @@ -1,38 +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"> - <title>Search Infrastructure Extension Points</title> -</head> -<body> - -<center> -<h1> -Eclipse Platform Search</h1></center> -This document lists all of the extension points that the search plug-in makes -available to tool developers. -<p>All XML sub-elements defined in the individual extension point documents -may appear more than once inside an extension element. For example, a <tt>org.eclipse.search.searchPages</tt> -extension may contain several instances of <tt>page</tt> elements. Although -making one extension per sub-element is not technically incorrect, we recommend -grouping for consistent style. It can also improve platform startup time -because there will be fewer extensions to process. -<br> -<hr WIDTH="100%"> -<h1> -Extension Points</h1> -The following extension points can be used to extend the capabilities -of the search infrastructure: -<ul> -<li> -<a href="org_eclipse_search_searchPages.html">org.eclipse.search.searchPages</a></li> -<li> -<a href="org_eclipse_search_searchResultSorters.html">org.eclipse.search.searchResultSorters</a></li> -</ul> - -<p><br> -<p> <a href="hglegal2002.htm"><img src="ngibmcpy2002.gif" alt="Copyright IBM Corporation 2000, 2002. All Rights Reserved." border="0" width="324" height="14"></a> -</p> - -</body> -</html> diff --git a/org.eclipse.search/doc/org_eclipse_search_searchPages.html b/org.eclipse.search/doc/org_eclipse_search_searchPages.html deleted file mode 100644 index 9f2a4ad5985..00000000000 --- a/org.eclipse.search/doc/org_eclipse_search_searchPages.html +++ /dev/null @@ -1,98 +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"><title>Eclipse Search Infrastructure Extension Point: Search Pages</title></head> - -<body> - -<center> -<h1> -Search Pages</h1></center> -<b><i>Identifier: </i></b>org.eclipse.search.searchPages -<p><b><i>Description</i>: </b>This extension point allows a plug-in to register -search pages for specialized searches. When the search action is performed on -a resource, the search infrastructure locates the most specific registered search -page for it. - -</p><p><b><i>Configuration Markup:</i></b> -</p><p><tt> <!ELEMENT page EMPTY></tt> -<br><tt> <!ATTLIST page</tt> -<br><tt> id CDATA #REQUIRED</tt> -<br><tt> label CDATA #REQUIRED</tt> -<br><tt> class CDATA #REQUIRED</tt> -<br><tt> icon CDATA #IMPLIED</tt> -<br><tt> sizeHint CDATA #REQUIRED</tt> -<br><tt> tabPosition CDATA #IMPLIED</tt> -<br><tt> extensions CDATA #IMPLIED</tt> -<br><tt> showScopeSection CDATA #IMPLIED</tt><br> -<tt> enabled CDATA #IMPLIED</tt> -<br><tt> ></tt> -</p><ul><li><b>id</b> - a unique name that will be used to identify this search page</li> - -<li> -<b>label</b> - a translatable label that will be used in the search page tab</li> - -<li> -<b>class</b> - a name of the class that implements <tt>org.eclipse.search.ui.ISearchPage</tt>. -We recommend subclassing <tt>org.eclipse.jface.dialogs.DialogPage</tt>. -</li> - -<li> -<b>icon</b> - a relative name of the image that will be used for all resources -that match the specified extensions. If omitted, the -search page's tab will only contain a label.</li> - -<li> -<b>sizeHint</b> - a hint for the initial size of the page. This is a string -containing the width and height separated by comma (e.g. "50, 60"). In the case -this hint is omitted the page will be no larger than the other pages.</li> - -<li> -<b>tabPosition</b> - an integer defining where the page is placed in the -page book. The value does not define the absolute position but the position -relative to the other pages. The ordering of pages is as follows: <ol> - <li>if the tabPosition is not specified for a page then <tt>Integer.MAX_VALUE / 2</tt> is used</li> - <li>the page with the lower value comes first. If the values are equal -then the pages are are ordered alphabetically according to their labels</li> - </ol> -</li> - -<li> -<b>extensions</b> - a comma separated list with file extensions on which the -search page can operate. Each extension must also include a weight (0 meaning -lowest weight) which enables the search infrastructure to find the best fitting -page. The weight is separated from the extension by a colon. -If a search page can search all possible resources then <tt>"*"</tt> can be used.</li> - -<li> -<b>showScopeSection</b> - if this attribute is missing or set to <tt>"false"</tt> then the -scope section is not shown in the Search dialog. To see the scope section this -attribute has to be set to <tt>"true"</tt>. Plug-ins which add their own Search page and -want to see the scope section have to add this to their plugin.xml.</li><li><b>enabled</b> - if this attribute is missing or set to <tt>"false"</tt> - then the page is not initially shown in the Search dialog. The page can -be activated by the user via the "Customize..." button on the Search dialog.</li> - - -</ul> -<b><i>Examples:</i></b> -<p>The following is an example of a search page extension definition: -</p><p><tt> <extension point="org.eclipse.search.searchPages"></tt> -<br><tt> <page</tt> -<br><tt> id="org.eclipse.search.ui.text.TextSearchPage"</tt> -<br><tt> label="Text Search"</tt> -<br><tt> icon="icons/full/obj16/tsearch_pref.gif"</tt> -<br><tt> sizeHint="250,160"</tt> -<br><tt> tabPosition="1"</tt> -<br><tt> extensions="*:1"</tt> -<br><tt> showScopeSection="true"</tt> -<br><tt> class="org.eclipse.search.ui.text.TextSearchPage"</tt> -<br><tt> </page></tt> -<br><tt> </extension></tt> - -</p><p><b><i>Supplied Implementation: </i></b>The search infrastructure provides - a search page for full-text search. -</p> - -<p><br> -<p> <a href="hglegal2002.htm"><img src="ngibmcpy2002.gif" alt="Copyright IBM Corporation 2000, 2002. All Rights Reserved." border="0" width="324" height="14"></a> -</p> - -</body></html>
\ No newline at end of file diff --git a/org.eclipse.search/doc/org_eclipse_search_searchResultSorters.html b/org.eclipse.search/doc/org_eclipse_search_searchResultSorters.html deleted file mode 100644 index ec634c4ec99..00000000000 --- a/org.eclipse.search/doc/org_eclipse_search_searchResultSorters.html +++ /dev/null @@ -1,73 +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="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]"> - <title>Eclipse Search Infrastructure Extension Point: Result Sorters</title> -</head> -<body> - -<center> -<h1> -Result Sorters</h1></center> -<b><i>Identifier: </i></b>org.eclipse.search.searchResultSorters -<p><b><i>Description</i>: </b>This extension point allows a plug-in to -contribute search result sorters to the search result view's <i>Sort</i> -context menu. -<p><b><i>Configuration Markup:</i></b> -<p><tt> <!ELEMENT sorter EMPTY></tt> -<br><tt> <!ATTLIST sorter</tt> -<br><tt> id CDATA #REQUIRED</tt> -<br><tt> pageId CDATA #REQUIRED</tt> -<br><tt> label CDATA #REQUIRED</tt> -<br><tt> tooltip CDATA #IMPLIED</tt> -<br><tt> icon CDATA #IMPLIED</tt> -<br><tt> class CDATA #REQUIRED</tt> -<br><tt> ></tt> -<ul> -<li> -<b>id</b> - a unique name that will be used to identify this search -result sorter.</li> - -<li> -<b>pageId</b> - the ID of a registered search page for which the sorter -will be activated. "*" activates the sorter for all pages.</li> - -<li> -<b>label</b> - a translatable label that will be used as the menu item's -label.</li> - -<li> -<b>tooltip</b> - a translatable text that will be used as the menu -item's tool tip . If omitted, the menu item will have no tool tip.</li> - -<li> -<b>icon</b> - a relative name of the image that will be shown in the -context menu along with the label. If omitted, the menu entry will only -contain a label.</li> - -<li> -<b>class</b> - a name of the class that extends <tt>org.eclipse.jface.viewers.ViewerSorter</tt>.</li> -</ul> -<b><i>Examples:</i></b> -<p><tt>The following is an example of a search page extension definition:</tt> -<p><tt> <extension point="org.eclipse.search.searchResultSorters"></tt> -<br><tt> <sorter</tt> -<br><tt> id="org.eclipse.search.internal.ui.FileNameSorter"</tt> -<br><tt> pageId="*"</tt> -<br><tt> label="%FileNameSorter.label"</tt> -<br><tt> tooltip="%FileNameSorter.tooltip"</tt> -<br><tt> icon="icons/full/ecl16/search_sort.gif"</tt> -<br><tt> class="org.eclipse.search.internal.ui.FileNameSorter"></tt> -<br><tt> </sorter></tt> -<br><tt> </extension></tt> - -<p><b><i>Supplied Implementation: </i></b>The search infrastructure -provides a sorter that sorts the matches by the resource name.</p> - -<p><br> -<p> <a href="hglegal2002.htm"><img src="ngibmcpy2002.gif" alt="Copyright IBM Corporation 2000, 2002. All Rights Reserved." border="0" width="324" height="14"></a> -</p> - -</body> -</html> diff --git a/org.eclipse.search/icons/full/clcl16/search_goto.gif b/org.eclipse.search/icons/full/clcl16/search_goto.gif Binary files differdeleted file mode 100644 index 80484787d21..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_goto.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_history.gif b/org.eclipse.search/icons/full/clcl16/search_history.gif Binary files differdeleted file mode 100644 index 151fe137e33..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_history.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_next.gif b/org.eclipse.search/icons/full/clcl16/search_next.gif Binary files differdeleted file mode 100644 index 8392f3345c5..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_next.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_prev.gif b/org.eclipse.search/icons/full/clcl16/search_prev.gif Binary files differdeleted file mode 100644 index 9b278e6fa81..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_prev.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_rem.gif b/org.eclipse.search/icons/full/clcl16/search_rem.gif Binary files differdeleted file mode 100644 index 12a9167c59d..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_rem.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_remall.gif b/org.eclipse.search/icons/full/clcl16/search_remall.gif Binary files differdeleted file mode 100644 index 2c069ab3f43..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_remall.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_sortmatch.gif b/org.eclipse.search/icons/full/clcl16/search_sortmatch.gif Binary files differdeleted file mode 100644 index 9ed470d02f7..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_sortmatch.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/clcl16/search_stop.gif b/org.eclipse.search/icons/full/clcl16/search_stop.gif Binary files differdeleted file mode 100644 index 4eb53ec41c4..00000000000 --- a/org.eclipse.search/icons/full/clcl16/search_stop.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/ctool16/search.gif b/org.eclipse.search/icons/full/ctool16/search.gif Binary files differdeleted file mode 100644 index 6dc3ebefc92..00000000000 --- a/org.eclipse.search/icons/full/ctool16/search.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/cview16/searchres.gif b/org.eclipse.search/icons/full/cview16/searchres.gif Binary files differdeleted file mode 100644 index 8b39ab3b8be..00000000000 --- a/org.eclipse.search/icons/full/cview16/searchres.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_goto.gif b/org.eclipse.search/icons/full/dlcl16/search_goto.gif Binary files differdeleted file mode 100644 index 4d8cd04e403..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_goto.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_history.gif b/org.eclipse.search/icons/full/dlcl16/search_history.gif Binary files differdeleted file mode 100644 index ee26f79a803..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_history.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_next.gif b/org.eclipse.search/icons/full/dlcl16/search_next.gif Binary files differdeleted file mode 100644 index 6cbeced2629..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_next.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_prev.gif b/org.eclipse.search/icons/full/dlcl16/search_prev.gif Binary files differdeleted file mode 100644 index a3441a06280..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_prev.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_rem.gif b/org.eclipse.search/icons/full/dlcl16/search_rem.gif Binary files differdeleted file mode 100644 index 7e0ad4aed42..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_rem.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_remall.gif b/org.eclipse.search/icons/full/dlcl16/search_remall.gif Binary files differdeleted file mode 100644 index 7ace43e8a73..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_remall.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_sortmatch.gif b/org.eclipse.search/icons/full/dlcl16/search_sortmatch.gif Binary files differdeleted file mode 100644 index 8a47d61be8d..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_sortmatch.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dlcl16/search_stop.gif b/org.eclipse.search/icons/full/dlcl16/search_stop.gif Binary files differdeleted file mode 100644 index 7f0f9b925f8..00000000000 --- a/org.eclipse.search/icons/full/dlcl16/search_stop.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/dtool16/search.gif b/org.eclipse.search/icons/full/dtool16/search.gif Binary files differdeleted file mode 100644 index 5fe80f3fc6e..00000000000 --- a/org.eclipse.search/icons/full/dtool16/search.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_goto.gif b/org.eclipse.search/icons/full/elcl16/search_goto.gif Binary files differdeleted file mode 100644 index d02e028054b..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_goto.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_history.gif b/org.eclipse.search/icons/full/elcl16/search_history.gif Binary files differdeleted file mode 100644 index d1e6b85ecf4..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_history.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_next.gif b/org.eclipse.search/icons/full/elcl16/search_next.gif Binary files differdeleted file mode 100644 index 1d0b40adc61..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_next.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_prev.gif b/org.eclipse.search/icons/full/elcl16/search_prev.gif Binary files differdeleted file mode 100644 index 13729577c02..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_prev.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_rem.gif b/org.eclipse.search/icons/full/elcl16/search_rem.gif Binary files differdeleted file mode 100644 index 310510ee588..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_rem.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_remall.gif b/org.eclipse.search/icons/full/elcl16/search_remall.gif Binary files differdeleted file mode 100644 index 33908b12653..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_remall.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_sortmatch.gif b/org.eclipse.search/icons/full/elcl16/search_sortmatch.gif Binary files differdeleted file mode 100644 index 336c0ec3d09..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_sortmatch.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/elcl16/search_stop.gif b/org.eclipse.search/icons/full/elcl16/search_stop.gif Binary files differdeleted file mode 100644 index a519f44d453..00000000000 --- a/org.eclipse.search/icons/full/elcl16/search_stop.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/etool16/search.gif b/org.eclipse.search/icons/full/etool16/search.gif Binary files differdeleted file mode 100644 index 57ed3b4f6dd..00000000000 --- a/org.eclipse.search/icons/full/etool16/search.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/eview16/searchres.gif b/org.eclipse.search/icons/full/eview16/searchres.gif Binary files differdeleted file mode 100644 index 7425e604f91..00000000000 --- a/org.eclipse.search/icons/full/eview16/searchres.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/obj16/searchm_obj.gif b/org.eclipse.search/icons/full/obj16/searchm_obj.gif Binary files differdeleted file mode 100644 index 657b67e716e..00000000000 --- a/org.eclipse.search/icons/full/obj16/searchm_obj.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/obj16/tsearch_dpdn_obj.gif b/org.eclipse.search/icons/full/obj16/tsearch_dpdn_obj.gif Binary files differdeleted file mode 100644 index e6be5623860..00000000000 --- a/org.eclipse.search/icons/full/obj16/tsearch_dpdn_obj.gif +++ /dev/null diff --git a/org.eclipse.search/icons/full/obj16/tsearch_obj.gif b/org.eclipse.search/icons/full/obj16/tsearch_obj.gif Binary files differdeleted file mode 100644 index 73ac91bddbc..00000000000 --- a/org.eclipse.search/icons/full/obj16/tsearch_obj.gif +++ /dev/null diff --git a/org.eclipse.search/old_buildnotes_search_2_0.html b/org.eclipse.search/old_buildnotes_search_2_0.html deleted file mode 100644 index d36c4a7942c..00000000000 --- a/org.eclipse.search/old_buildnotes_search_2_0.html +++ /dev/null @@ -1,925 +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="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]"> - - <meta name="Author" content="IBM"><title>Eclipse Platform Release Notes - Search</title></head><body> - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020618 - - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>Reverted File/Text search back to only ignore derived resoureces<br></li><li>Removed dependency on Team Support Core plug-in<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F06%2F06&chfieldto=2002%2F06%2F18&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/06/06 and 2002/06/18.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020606 - - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>Reverted File/Text search back to only ignore derived resoureces<br> -</li><li>Removed dependency on Team Support Core plug-in<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F05%2F31&chfieldto=2002%2F06%2F06&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/05/31 and 2002/06/06.<br> -<br> -<hr size="1" width="100%"><br> - - - - - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020531 - - - - - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>File search ignores derived and to be ignored resource (see Team preference page)</li><li>Text search ignores binary files<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F05%2F28&chfieldto=2002%2F05%2F31&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/05/28 and 2002/05/31.<br> -<br> -<hr size="1" width="100%"> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020528 - - - - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F05%2F21&chfieldto=2002%2F05%2F28&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/05/21 and 2002/05/28.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - - - Eclipse Build Input 20020521 - - - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F05%2F18&chfieldto=2002%2F05%2F21&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/05/18 and 2002/05/21.<br> -<br> -<hr size="1" width="100%"> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - - Eclipse Build Input 20020518 - - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>Global menu for Search actions</li><li>Replace is now available on text search results<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F05%2F14&chfieldto=2002%2F05%2F18&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/05/14 and 2002/05/18.<br> -<br> -<hr size="1" width="100%"> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - - - Eclipse Build Input 20020514 - - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F05%2F08&chfieldto=2002%2F05%2F14&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/05/08 and 2002/05/14.<br> -<br> -<hr size="1" width="100%"><br> - - - - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - - Eclipse Build Input 20020508 - - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>The visible search pages can be configured in the Search dialog.<br> -</li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F30&chfieldto=2002%2F05%2F08&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/30 and 2002/05/08.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - - - Eclipse Build Input 20020430 - - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>Removed the deprecated working set API</li><li>Search dialog no longer reserves space for scope for all pages but only those that require it<br></li> - -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F23&chfieldto=2002%2F04%2F30&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/23 and 2002/04/30.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - - - Eclipse Build Input 20020423 - - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F19&chfieldto=2002%2F04%2F23&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/18 and 2002/04/23.<br> -<br> -<hr size="1" width="100%"> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - - - Eclipse Build Input 20020418 - - - - - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F16&chfieldto=2002%2F04%2F19&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/16 and 2002/04/18.<br> -<br> -<hr size="1" width="100%"> - - - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - Eclipse Build Input 20020416 - - - - - -<h2> What's new in this drop</h2> -<ul> -<li>Search no longer uses its own implementation of working sets but takes -advantage of the workbench working set support. As a consequence you will -have to redefine your existing working sets.<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F11&chfieldto=2002%2F04%2F17&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/11 and 2002/04/16.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - - - Eclipse Build Input 20020411 - - - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F09&chfieldto=2002%2F04%2F12&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/09 -and 2002/04/11.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - - - Eclipse Build Input 20020409 - - - -<h2> What's new in this drop</h2> -<ul> -<li><i>Text Search</i> has been changed to <i>File Search</i> and now allows to search for files with a given file name pattern.<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F04%2F02&chfieldto=2002%2F04%2F09&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/04/02 -and 2002/04/09.<br> -<br> -<hr size="1" width="100%"><br> - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - - Eclipse Build Input 20020402 - - -<h2> What's new in this drop</h2> -<ul> -<li><br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F03%2F19&chfieldto=2002%2F03%2F26&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/03/26 -and 2002/04/02.<br> -<br> -<hr size="1" width="100%"><br> - - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - Eclipse Build Input 20020326 - -<h2> What's new in this drop</h2> -<ul> -<li>Text search also finds matches in dirty editors.<br></li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F03%2F26&chfieldto=2002%2F04%2F02&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - - to see BRs which have been marked as RESOLVED or CLOSED between 2002/03/19 -and 2002/03/26.<br> -<br> -<hr size="1" width="100%"><br> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - - Eclipse Build Input 20020226 -<h2> What's new in this drop</h2> -<ul> - <li>Previous file name patterns are now available through a combo box.</li> - <li>The file name pattern is only derived the first time from the selection -and after that the previous value is used to initialize the field.<br> - </li> -</ul> -<h2>Problem Reports</h2> -<a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F02%2F14&chfieldto=2002%2F02%2F26&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - to see BRs which have been marked as RESOLVED or CLOSED between 2002/02/14 -and 2002/02/26.<br> -<br> -<hr size="1" width="100%"><br> -<br> - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Build Input 20020214 -<h2> What's new in this drop</h2> - -<ul> - <li>Reuse of editors when stepping through search matches now managed -by platform and no longer directly by the Search plug-in.<br> - </li> - -</ul> - -<h2>Problem Reports</h2> - <a href="http://dev.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=CLOSED&chfield=bug_status&chfieldfrom=2002%2F02%2F05&chfieldto=2002%2F02%2F14&product=Platform&component=Search&cmdtype=doit&&order=Bug+Number"> - Click here</a> - to see BRs which have been marked as RESOLVED or CLOSED between 2002/02/05 -and 2002/02/14.<br> - <br> - -<hr size="1" width="100%"><br> - -<h1>Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20020205 -<h2> What's new in this drop</h2> - -<h3> API changes</h3> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=8611">8611</a> - NPE in text search with Compare to a Version editor open<br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=9007">9007</a> - Working Set; OK button not disabled<br> - -<h2> Problem reports closed</h2> - -<hr size="1" width="100%"><br> - -<h1> Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20020129 -<h2>What's new in this drop</h2> - -<ul> - <li>A new attribute called <i>showScopeSection</i> has been added to - the markup language for Search pages. If this attribute is missing or set - to <tt>false</tt> then the scope section is not shown in the Search dialog. - To see the scope section this attribute has to be set to <tt>true</tt> -. Plug-ins which add their own Search page and want to see the scope section - will have to add the new attribute to their plugin.xml</li> - -</ul> - -<h3> API changes</h3> - -<ul> - <li>Activation of the Search view has been moved from the dialog to -the individual Search page. Plug-ins which want the Search page to appear - when Search is invoked have to call <tt>SearchUI.activateSearchResultView()</tt><br> - </li> - -</ul> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=7918">7918</a> - Missing busy cursor in search dialog when flipping pages<br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=7919">7919</a> - Search: scope section doesn't apply to Help search<br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=8024">8024</a> - SearchResultsView opens without calling SearchUI.activateSearchView<br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=8025">8025</a> - Scope section added to ISearchPage<br> - -<h2> Problem reports closed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=8456">8456</a> - Widget is disposed error in Search<br> - <br> - <br> - -<hr size="1" width="100%"> -<h1>Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20020122 -<h2> What's new in this drop</h2> - -<h3> API changes</h3> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=7813">7813</a> - NPE in SearchPageDescriptor.readExtensionScorePairs/StringTo<br> - -<h2> Problem reports closed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=4066">4066</a> - Default extension in text search is often wrong (1GHFMPL)<br> - <br> - -<hr size="1" width="100%"> -<h1> Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20011218 -<h2> What's new in this drop</h2> - -<h3> API changes</h3> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - APIs added for 2.0 are now flagged with <b>@since 2.0</b>. - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=6836">6836</a> - Working Sets Dialog: Mnemonics, issues -<hr size="1" width="100%"> -<h1> Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20011211 -<h2> What's new in this drop</h2> - -<h3> API changes</h3> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=5868">5868</a> - Define working set does too much work in the UI thread <br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=5620">5620</a> - Search: control keys for navigating the list of search results - -<hr size="1" width="100%"> -<h1> Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20011206 -<h2> What's new in this drop</h2> - -<h3> API changes</h3> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=6119">6119</a> - cannot delete a working set <br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=6264">6264</a> - Search results don't have initial selection -<hr size="1" width="100%"> -<h1> Eclipse Platform Build Notes<br> - Search</h1> - Eclipse Integration Build 20011204 -<h2> What's new in this drop</h2> - -<h3> API changes</h3> - -<h3> API additions</h3> - -<h3> Other highlights</h3> - -<h2> Known deficiencies</h2> - -<h2> Problem reports fixed</h2> - <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=3954">3954</a> - Search dialog does not need parentheses around label (1GF86BN) -<br> - <a href="http://dev.eclipse.org/bugs/show_bug.cgi?id=6435">6435</a> - Search again should move search to top of MRU list -<hr size="1" width="100%"> -<h1> Eclipse Platform Build Notes<br> - Search</h1> - Note: Previous build notes have been included in <i>Eclipse Platform - Build Notes - Java Development Tooling UI.</i><br> - -</body></html>
\ No newline at end of file diff --git a/org.eclipse.search/plugin.properties b/org.eclipse.search/plugin.properties deleted file mode 100644 index 749dad41a97..00000000000 --- a/org.eclipse.search/plugin.properties +++ /dev/null @@ -1,30 +0,0 @@ -######################################### -# (c) Copyright IBM Corp. 2000, 2002. -# All Rights Reserved. -######################################### - -pluginName= Search Support -providerName= Eclipse.org - -searchMarker= Search Marker - -searchPages= Search Pages -searchResultSorters= Search Result Sorters - -search= Search - -searchMenu.label= Se&arch -openFileSearchPageAction.label= &File... - -openSearchDialogAction.label= Se&arch...@Ctrl+H -openSearchDialogAction.tooltip= Search - -fileSearch= File Search -searchResultViewName= Search - -ResourcenameSorter.label= &Name -ResourcenameSorter.tooltip= Sort by Resource Name -ResourcePathSorter.label= &Path -ResourcePathSorter.tooltip= Sort by Resource Path - -SearchPreferencePage.label= Search diff --git a/org.eclipse.search/plugin.xml b/org.eclipse.search/plugin.xml deleted file mode 100644 index 430d9c4652f..00000000000 --- a/org.eclipse.search/plugin.xml +++ /dev/null @@ -1,138 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- ======================================================================= --> -<!-- Search Plugin --> -<!-- ======================================================================= --> -<plugin - name="%pluginName" - id="org.eclipse.search" - version="2.1.0" - provider-name="%providerName" - class="org.eclipse.search.internal.ui.SearchPlugin"> - -<requires> - <import plugin="org.apache.xerces"/> - <import plugin="org.eclipse.core.resources"/> - <import plugin="org.eclipse.ui"/> -</requires> - -<runtime> - <library name="search.jar" > - <export name = "*"/> - </library> -</runtime> - - -<!-- Search extension point definitions --> - -<extension-point name="%searchPages" id="searchPages"/> -<extension-point name="%searchResultSorters" id="searchResultSorters"/> - - -<!-- Extensions --> - -<extension id="searchmarker" point="org.eclipse.core.resources.markers" name="%searchMarker"> - <super type="org.eclipse.core.resources.textmarker"/> - <attribute name="line"/> - <attribute name="potentialMatch"/> -</extension> - -<extension - point="org.eclipse.ui.markerImageProviders"> - <imageprovider - id="org.eclipse.ui.searchMarkerProvider" - markertype="org.eclipse.search.searchmarker" - icon="icons/full/obj16/searchm_obj.gif"> - </imageprovider> -</extension> - -<extension point="org.eclipse.ui.actionSets"> - <actionSet - id="org.eclipse.search.searchActionSet" - label="%search" - visible="true"> - - <!-- =================================================================== --> - <!-- Search Menu --> - <!-- =================================================================== --> - - <menu - id="org.eclipse.search.menu" - label="%searchMenu.label" - path="navigate"> - <groupMarker name="internalDialogGroup"/> <!-- not to be used by clients --> - <groupMarker name="dialogGroup"/> <!-- to be used by clients --> - <separator name="contextMenuActionsGroup"/> - </menu> - - <!-- dialog group --> - <action id="org.eclipse.search.OpenFileSearchPage" - menubarPath="org.eclipse.search.menu/internalDialogGroup" - label="%openFileSearchPageAction.label" - icon="icons/full/obj16/tsearch_obj.gif" - class="org.eclipse.search.internal.ui.OpenFileSearchPageAction"/> - - <action id="org.eclipse.search.OpenSearchDialog" - toolbarPath="Normal/Search" - menubarPath="org.eclipse.search.menu/internalDialogGroup" - label="%openSearchDialogAction.label" - tooltip="%openSearchDialogAction.tooltip" - icon="icons/full/ctool16/search.gif" - accelerator="Ctrl+H" - class="org.eclipse.search.internal.ui.OpenSearchDialogAction"/> - - </actionSet> -</extension> - -<extension point="org.eclipse.ui.views"> - <view - id="org.eclipse.search.SearchResultView" - name="%searchResultViewName" - category="org.eclipse.ui" - class="org.eclipse.search.internal.ui.SearchResultView" - icon="icons/full/cview16/searchres.gif"> - </view> -</extension> - -<extension point="org.eclipse.search.searchPages"> - <page - id="org.eclipse.search.internal.ui.text.TextSearchPage" - label="%fileSearch" - icon="icons/full/obj16/tsearch_obj.gif" - sizeHint="250,160" - tabPosition="1" - extensions="*:1" - showScopeSection="true" - class="org.eclipse.search.internal.ui.text.TextSearchPage"> - </page> -</extension> - -<extension point="org.eclipse.search.searchResultSorters"> - <sorter - id="org.eclipse.search.internal.ui.ResourcenameSorter" - pageId="org.eclipse.search.internal.ui.text.TextSearchPage" - label="%ResourcenameSorter.label" - tooltip="%ResourcenameSorter.tooltip" - icon="icons/full/clcl16/search_sortmatch.gif" - class="org.eclipse.search.internal.ui.text.ResourcenameSorter"> - </sorter> - <sorter - id="org.eclipse.search.internal.ui.ResourcePathSorter" - pageId="org.eclipse.search.internal.ui.text.TextSearchPage" - label="%ResourcePathSorter.label" - tooltip="%ResourcePathSorter.tooltip" - icon="icons/full/clcl16/search_sortmatch.gif" - class="org.eclipse.search.internal.ui.text.ResourcePathSorter"> - </sorter> -</extension> - -<extension - point="org.eclipse.ui.preferencePages"> - <page name="%SearchPreferencePage.label" - id="org.eclipse.search.preferences.SearchPreferencePage" - class="org.eclipse.search.internal.ui.SearchPreferencePage" - category="org.eclipse.ui.preferencePages.Workbench"> - </page> -</extension> - -</plugin>
\ No newline at end of file diff --git a/org.eclipse.search/scripts/exportplugin.xml b/org.eclipse.search/scripts/exportplugin.xml deleted file mode 100644 index fafcb59d014..00000000000 --- a/org.eclipse.search/scripts/exportplugin.xml +++ /dev/null @@ -1,31 +0,0 @@ -<project name="org.eclipse.search" default="export" basedir=".."> - <target name="init"> - <tstamp/> - <property name="destdir" value="../../plugin-export" /> - <property name="plugin" value="org.eclipse.search" /> - <property name="version" value="_2.1.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}/search.jar" - basedir="bin" - /> - <copy file="plugin.xml" todir="${dest}"/> - <copy file="plugin.properties" todir="${dest}"/> - <copy todir="${dest}/icons"> - <fileset dir="icons" /> - </copy> - <zip zipfile="${dest}/searchsrc.zip"> - <fileset dir="search" /> - </zip> - </target> -</project> diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/ISearchScope.java b/org.eclipse.search/search/org/eclipse/search/internal/core/ISearchScope.java deleted file mode 100644 index c924ce8fbe2..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/ISearchScope.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core; - -import org.eclipse.core.resources.IResource; - -/** - * Defines a scope to which search results are limited. - */ -public interface ISearchScope { - - /** - * Checks whether the given element is enclosed by - * this scope or not. - * - * @param element the resource to be checked - * @return <code>true</code> if the resource is inside the search scope - * - */ - public boolean encloses(IResource element); - - /** - * Returns a human readable description of this scope - * - * @return the description of this scope as <code>String</code> - * - */ - public String getDescription(); -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/SearchScope.java b/org.eclipse.search/search/org/eclipse/search/internal/core/SearchScope.java deleted file mode 100644 index a32ae2226be..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/SearchScope.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - -import org.eclipse.jface.util.Assert; - -/** - * A default implementation of <code>ISearchScope</code>. - */ -public class SearchScope implements ISearchScope { - - private List fElements; - private String fDescription; - - public SearchScope(String description) { - Assert.isNotNull(description); - fDescription= description; - fElements= new ArrayList(5); - } - - public SearchScope(String description, IResource[] resources) { - Assert.isNotNull(description); - int resourceCount= resources.length; - fDescription= description; - fElements= new ArrayList(resourceCount + 5); - for (int i= 0; i < resourceCount; i++) - fElements.add(resources[i]); - } - - /* - * @see ISearchScope#add(IResource) - */ - public void add(IResource element) { - fElements.add(element); - } - - /* - * Implements method from ISearchScope - */ - public boolean encloses(IResource element) { - IPath elementPath= element.getFullPath(); - Iterator iter= elements(); - while (iter.hasNext()) { - IResource resource= (IResource)iter.next(); - if (resource.getFullPath().isPrefixOf(elementPath)) - return true; - } - return false; - } - - /* - * Implements method from ISearchScope - */ - public String getDescription() { - return fDescription; - } - - /** - * Returns the search scope elements - */ - protected Iterator elements() { - return fElements.iterator(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/AmountOfWorkCalculator.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/AmountOfWorkCalculator.java deleted file mode 100644 index 25c1f45bd32..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/AmountOfWorkCalculator.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core.text; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.MultiStatus; - -import org.eclipse.search.internal.core.ISearchScope; - -/** - * The visitor that does the actual work. - */ -public class AmountOfWorkCalculator extends TypedResourceVisitor { - private ISearchScope fScope; - private int fResult; - - AmountOfWorkCalculator(MultiStatus status) { - super(status); - } - - protected boolean visitFile(IFile file) throws CoreException { - if (fScope.encloses(file) && !file.isDerived()) - fResult++; - return true; - } - - public int process(Collection projects, ISearchScope scope) { - fResult= 0; - fScope= scope; - - Iterator i= projects.iterator(); - while(i.hasNext()) { - IProject project= (IProject)i.next(); - int save= fResult; - try { - project.accept(this); - } catch (CoreException ex) { - addToStatus(ex); - } - // Project doesn't contain any files that are in scope - if (save == fResult) - i.remove(); - } - - return fResult; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/ITextSearchResultCollector.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/ITextSearchResultCollector.java deleted file mode 100644 index 0fa5cc47c65..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/ITextSearchResultCollector.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core.text; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -public interface ITextSearchResultCollector { - - /** - * Returns the progress monitor used to setup and report progress. - */ - public IProgressMonitor getProgressMonitor(); - - /** - * Called before the actual search starts. - */ - public void aboutToStart() throws CoreException; - - /** - * Accepts the given search result. - * @param resource the resource in which the match has been found. - * @param line the line containing the match - * @param int start position from the beginning of the file. Start position - * is zero based. - * @param length the length of the match. - * @param lineNumber the line number of the match. - */ - public void accept(IResource resource, String line, int start, int length, int lineNumber) throws CoreException; - - /** - * Called when the search has ended. - */ - public void done() throws CoreException; -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngine.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngine.java deleted file mode 100644 index b77f3bbe07f..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngine.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core.text; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; - -import org.eclipse.jface.util.Assert; - -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.core.ISearchScope; -import org.eclipse.search.internal.ui.SearchMessages; - -public class TextSearchEngine { - - /** - * Search for the given pattern. - */ - public IStatus search(IWorkspace workspace, String pattern, String options, ISearchScope scope, ITextSearchResultCollector collector) { - Assert.isNotNull(workspace); - Assert.isNotNull(pattern); - Assert.isNotNull(scope); - Assert.isNotNull(collector); - - IProgressMonitor monitor= collector.getProgressMonitor(); - - IProject[] projects= workspace.getRoot().getProjects(); - Collection openProjects= new ArrayList(10); - for (int i= 0; i < projects.length; i++) { - IProject project= projects[i]; - if (project.isOpen()) - openProjects.add(project); - } - String message= SearchMessages.getString("TextSearchEngine.statusMessage"); //$NON-NLS-1$ - MultiStatus status= new MultiStatus(SearchUI.PLUGIN_ID, IStatus.OK, message, null); - if (!openProjects.isEmpty()) { - int amountOfWork= (new AmountOfWorkCalculator(status)).process(openProjects, scope); - try { - monitor.beginTask("", amountOfWork); //$NON-NLS-1$ - if (amountOfWork > 0) { - Integer[] args= new Integer[] {new Integer(1), new Integer(amountOfWork)}; - monitor.setTaskName(SearchMessages.getFormattedString("TextSearchEngine.scanning", args)); //$NON-NLS-1$ - } - collector.aboutToStart(); - TextSearchVisitor visitor= new TextSearchVisitor(pattern, options, scope, collector, status, amountOfWork); - visitor.process(openProjects); - } catch (CoreException ex) { - status.add(ex.getStatus()); - } finally { - monitor.done(); - try { - collector.done(); - } catch (CoreException ex) { - status.add(ex.getStatus()); - } - } - } - return status; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchScope.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchScope.java deleted file mode 100644 index 9f48c07c6d1..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchScope.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core.text; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; - -import org.eclipse.ui.IWorkingSet; - -import org.eclipse.search.internal.core.SearchScope; -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.util.StringMatcher; - -/** - * A special text search scope that take file extensions into account. - */ -public class TextSearchScope extends SearchScope { - - private static class WorkspaceScope extends TextSearchScope { - - private WorkspaceScope() { - super(SearchMessages.getString("WorkspaceScope")); //$NON-NLS-1$ - } - - public void add(IResource element) { - // do nothing - } - - /** - * @see ISearchScope#encloses(Object) - */ - public boolean encloses(IResource element) { - if (element instanceof IFile && skipFile((IFile)element)) - return false; - return true; - } - } - - private Set fExtensions= new HashSet(3); - - /** - * Returns a new Workbench scope. - */ - public static TextSearchScope newWorkspaceScope() { - return new WorkspaceScope(); - } - - public TextSearchScope(String description) { - super(description); - } - - public TextSearchScope(String description, IResource[] resources) { - super(description, resources); - } - - public TextSearchScope(String description, IAdaptable[] elements) { - super(description, convertToResources(elements)); - - } - - public TextSearchScope(String description, IWorkingSet[] workingSets) { - super(description, convertToResources(getElements(workingSets))); - } - - private static IResource[] convertToResources(IAdaptable[] elements) { - int length= elements.length; - Set resources= new HashSet(length); - for (int i= 0; i < length; i++) { - IResource resource= (IResource)elements[i].getAdapter(IResource.class); - if (resource != null) - resources.add(resource); - } - return (IResource[])resources.toArray(new IResource[resources.size()]); - } - - private static IAdaptable[] getElements(IWorkingSet[] workingSets) { - int length= workingSets.length; - Set elements= new HashSet(length); - for (int i= 0; i < length; i++) { - elements.addAll(Arrays.asList(workingSets[i].getElements())); - } - return (IAdaptable[])elements.toArray(new IAdaptable[elements.size()]); - } - - /** - * Adds an extension to the scope. - */ - public void addExtension(String extension) { - fExtensions.add(new StringMatcher(extension, true, false)); - } - /** - * Adds all string patterns contained in <code>extensions</code> to this - * scope. The allowed pattern characters are <code>*</code> for any character - * and <code>?</code> for one character. - */ - public void addExtensions(Set extensions) { - if (extensions == null) - return; - Iterator iter= extensions.iterator(); - while (iter.hasNext()) { - Object obj= iter.next(); - if (obj instanceof String) - addExtension((String)obj); - } - } - - /* - * Implements method from ISearchScope - */ - public boolean encloses(IResource element) { - if (element instanceof IFile && skipFile((IFile)element)) - return false; - return super.encloses(element); - } - - boolean skipFile(IFile file) { - if (file != null) { - Iterator iter= fExtensions.iterator(); - while (iter.hasNext()) { - if (((StringMatcher)iter.next()).match(file.getName())) - return false; - } - } - return true; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java deleted file mode 100644 index 7a415858683..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core.text; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; - -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.texteditor.ITextEditor; - -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.core.ISearchScope; -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.internal.ui.util.StringMatcher; - -/** - * The visitor that does the actual work. - */ -public class TextSearchVisitor extends TypedResourceVisitor { - protected static final int fgLF= '\n'; - protected static final int fgCR= '\r'; - - private String fPattern; - private ISearchScope fScope; - private ITextSearchResultCollector fCollector; - private String fOptions; - private IEditorPart[] fDirtyEditors; - - private IProgressMonitor fProgressMonitor; - private StringMatcher fMatcher; - private String fErrorMessage; - private Integer[] fMessageFormatArgs; - - private int fNumberOfScannedFiles; - private int fNumberOfFilesToScan; - private long fLastUpdateTime; - - protected int fPushbackChar; - protected boolean fPushback; - - - public TextSearchVisitor(String pattern, String options, ISearchScope scope, ITextSearchResultCollector collector, MultiStatus status, int fileCount) { - super(status); - fPattern= pattern; - fScope= scope; - fCollector= collector; - fPushback= false; - if (options != null) - fOptions= options; - else - fOptions= ""; //$NON-NLS-1$ - - fProgressMonitor= collector.getProgressMonitor(); - fMatcher= new StringMatcher(pattern, options.indexOf('i') != -1, false); - fNumberOfScannedFiles= 0; - fNumberOfFilesToScan= fileCount; - fMessageFormatArgs= new Integer[] { new Integer(0), new Integer(fileCount) }; - } - - public void process(Collection projects) { - Iterator i= projects.iterator(); - while(i.hasNext()) { - IProject project= (IProject)i.next(); - try { - project.accept(this); - } catch (CoreException ex) { - addToStatus(ex); - } - } - } - - /** - * Returns an array of all editors that have an unsaved content. If the identical content is - * presented in more than one editor, only one of those editor parts is part of the result. - * - * @return an array of all dirty editor parts. - */ - public static IEditorPart[] getDirtyEditors() { - Set inputs= new HashSet(); - List result= new ArrayList(0); - IWorkbench workbench= SearchPlugin.getDefault().getWorkbench(); - IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); - for (int i= 0; i < windows.length; i++) { - IWorkbenchPage[] pages= windows[i].getPages(); - for (int x= 0; x < pages.length; x++) { - IEditorPart[] editors= pages[x].getDirtyEditors(); - for (int z= 0; z < editors.length; z++) { - IEditorPart ep= editors[z]; - IEditorInput input= ep.getEditorInput(); - if (!inputs.contains(input)) { - inputs.add(input); - result.add(ep); - } - } - } - } - return (IEditorPart[])result.toArray(new IEditorPart[result.size()]); - } - - - protected boolean visitFile(IFile file) throws CoreException { - if (! fScope.encloses(file)) - return false; - - // Exclude to derived resources - if (file.isDerived()) - return false; - - if (fPattern.length() == 0) { - fCollector.accept(file, "", -1, 0, -1); //$NON-NLS-1$ - updateProgressMonitor(); - return true; - } - - try { - BufferedReader reader= null; - ITextEditor editor= findDirtyEditorFor(file); - if (editor != null) { - String s= editor.getDocumentProvider().getDocument(editor.getEditorInput()).get(); - reader= new BufferedReader(new StringReader(s)); - } else { - InputStream stream= file.getContents(false); - reader= new BufferedReader(new InputStreamReader(stream, ResourcesPlugin.getEncoding())); - } - int lineCounter= 1; - int charCounter=0; - boolean eof= false; - try { - while (!eof) { - StringBuffer sb= new StringBuffer(200); - int eolStrLength= readLine(reader, sb); - int lineLength= sb.length(); - int start= 0; - eof= eolStrLength == -1; - String line= sb.toString(); - StringMatcher.Position match; - while (start < lineLength) { - if ((match= fMatcher.find(line, start, lineLength)) != null) { - start= charCounter + match.getStart(); - int length= match.getEnd() - match.getStart(); - fCollector.accept(file, line.trim(), start, length, lineCounter); - start= match.getEnd(); - } - else // no match in this line - start= lineLength; - } - charCounter+= lineLength + eolStrLength; - lineCounter++; - if (fProgressMonitor.isCanceled()) - throw new OperationCanceledException(SearchMessages.getString("TextSearchVisitor.canceled")); //$NON-NLS-1$ - } - } finally { - if (reader != null) - reader.close(); - } - } catch (IOException e) { - String message= SearchMessages.getFormattedString("TextSearchVisitor.error", file.getFullPath()); //$NON-NLS-1$ - throw new CoreException(new Status(IStatus.ERROR, SearchUI.PLUGIN_ID, Platform.PLUGIN_ERROR, message, e)); - } - finally { - updateProgressMonitor(); - } - return true; - } - - private void updateProgressMonitor() { - fNumberOfScannedFiles++; - if (fNumberOfScannedFiles < fNumberOfFilesToScan) { - if (System.currentTimeMillis() - fLastUpdateTime > 1000) { - fMessageFormatArgs[0]= new Integer(fNumberOfScannedFiles+1); - fProgressMonitor.setTaskName(SearchMessages.getFormattedString("TextSearchVisitor.scanning", fMessageFormatArgs)); //$NON-NLS-1$ - fLastUpdateTime= System.currentTimeMillis(); - } - } - fProgressMonitor.worked(1); - if (fProgressMonitor.isCanceled()) - throw new OperationCanceledException(SearchMessages.getString("TextSearchVisitor.canceled")); //$NON-NLS-1$ - } - - private ITextEditor findDirtyEditorFor(IFile file) { - int i= 0; - while (i < fDirtyEditors.length) { - IEditorPart dirtyEditor= fDirtyEditors[i]; - IEditorInput input= dirtyEditor.getEditorInput(); - if (input instanceof IFileEditorInput && dirtyEditor instanceof ITextEditor) - if (((IFileEditorInput)input).getFile().equals(file)) - return (ITextEditor)dirtyEditor; - i++; - } - return null; - } - - protected int readLine(BufferedReader reader, StringBuffer sb) throws IOException { - int ch= -1; - if (fPushback) { - ch= fPushbackChar; - fPushback= false; - } - else - ch= reader.read(); - while (ch >= 0) { - if (ch == fgLF) - return 1; - if (ch == fgCR) { - ch= reader.read(); - if (ch == fgLF) - return 2; - else { - fPushbackChar= ch; - fPushback= true; - return 1; - } - } - sb.append((char)ch); - ch= reader.read(); - } - return -1; - } - - /* - * @see IResourceVisitor#visit(IResource) - */ - public boolean visit(IResource resource) { - fDirtyEditors= getDirtyEditors(); - return super.visit(resource); - } -} - diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TypedResourceVisitor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TypedResourceVisitor.java deleted file mode 100644 index dd51f725dd5..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TypedResourceVisitor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.core.text; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.MultiStatus; - -import org.eclipse.jface.util.Assert; - -public class TypedResourceVisitor implements IResourceVisitor { - - private MultiStatus fStatus; - - TypedResourceVisitor(MultiStatus status) { - Assert.isNotNull(status); - fStatus= status; - } - - public boolean visit(IResource resource) { - try { - switch(resource.getType()) { - case IResource.FILE: - return visitFile((IFile)resource); - case IResource.FOLDER: - return visitFolder((IFolder)resource); - case IResource.PROJECT: - return visitProject((IProject)resource); - default: - Assert.isTrue(false, "unknown resource type"); //$NON-NLS-1$ - } - return false; - } catch (CoreException ex) { - addToStatus(ex); - return false; - } - } - - protected boolean visitProject(IProject project) throws CoreException { - return true; - } - - protected boolean visitFolder(IFolder folder) throws CoreException { - return true; - } - - protected boolean visitFile(IFile file) throws CoreException { - return true; - } - - protected void addToStatus(CoreException ex) { - fStatus.add(ex.getStatus()); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java deleted file mode 100644 index 6173f27d657..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.Collections; -import java.util.Iterator; - -import org.eclipse.swt.SWTError; -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.widgets.Shell; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; - -public class CopyToClipboardAction extends Action { - - private SearchResultViewer fViewer; - - public CopyToClipboardAction(SearchResultViewer viewer) { - Assert.isNotNull(viewer); - fViewer= viewer; - setText(SearchMessages.getString("CopyToClipboardAction.label")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("CopyToClipboardAction.tooltip")); //$NON-NLS-1$ - } - - /* - * Implements method from IAction - */ - public void run() { - Shell shell= SearchPlugin.getActiveWorkbenchShell(); - if (shell == null) - return; - - ILabelProvider labelProvider= (ILabelProvider)fViewer.getLabelProvider(); - String lineDelim= System.getProperty("line.separator"); //$NON-NLS-1$ - StringBuffer buf= new StringBuffer(); - Iterator iter= getSelection(); - while (iter.hasNext()) { - if (buf.length() > 0) { - buf.append(lineDelim); - } - buf.append(labelProvider.getText(iter.next())); - } - - if (buf.length() > 0) { - Clipboard clipboard= new Clipboard(shell.getDisplay()); - try { - copyToClipbard(clipboard, buf.toString(), shell); - } finally { - clipboard.dispose(); - } - } - } - - private Iterator getSelection() { - ISelection s= fViewer.getSelection(); - if (s instanceof IStructuredSelection) - return ((IStructuredSelection)s).iterator(); - return Collections.EMPTY_LIST.iterator(); - } - - private void copyToClipbard(Clipboard clipboard, String str, Shell shell) { - try { - clipboard.setContents(new String[] { str }, new Transfer[] { TextTransfer.getInstance() }); - } catch (SWTError ex) { - if (ex.code != DND.ERROR_CANNOT_SET_CLIPBOARD) - throw ex; - String title= SearchMessages.getString("CopyToClipboardAction.error.title"); //$NON-NLS-1$ - String message= SearchMessages.getString("CopyToClipboardAction.error.message"); //$NON-NLS-1$ - if (MessageDialog.openQuestion(shell, title, message)) - copyToClipbard(clipboard, str, shell); - } - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/GotoMarkerAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/GotoMarkerAction.java deleted file mode 100644 index a4f39a4666c..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/GotoMarkerAction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -class GotoMarkerAction extends Action { - - private SearchResultViewer fViewer; - - public GotoMarkerAction(SearchResultViewer viewer) { - super(SearchMessages.getString("SearchResultView.gotoMarker.text")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_GOTO); - setToolTipText(SearchMessages.getString("SearchResultView.gotoMarker.tooltip")); //$NON-NLS-1$ - fViewer= viewer; - } - - public void run() { - fViewer.showResult(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ISearchHelpContextIds.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ISearchHelpContextIds.java deleted file mode 100644 index 42cd9e14597..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ISearchHelpContextIds.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.search.ui.SearchUI; - -public interface ISearchHelpContextIds { - - public static final String PREFIX= SearchUI.PLUGIN_ID + "."; //$NON-NLS-1$ - - public static final String SEARCH_DIALOG= PREFIX + "search_dialog_context"; //$NON-NLS-1$ - - public static final String TEXT_SEARCH_PAGE= PREFIX + "text_search_page_context"; //$NON-NLS-1$ - public static final String TYPE_FILTERING_DIALOG= PREFIX + "type_filtering_dialog_context"; //$NON-NLS-1$ - - public static final String SEARCH_VIEW= PREFIX + "search_view_context"; //$NON-NLS-1$ - - public static final String SEARCH_PREFERENCE_PAGE= PREFIX + "search_preference_page_context"; //$NON-NLS-1$ - - public static final String SELECT_ALL_ACTION = PREFIX + "select_all_action_context"; //$NON-NLS-1$ -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenFileSearchPageAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenFileSearchPageAction.java deleted file mode 100644 index 546bc77a004..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenFileSearchPageAction.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; - -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; - -import org.eclipse.search.ui.SearchUI; - -/** - * Opens the Search Dialog. - */ -public class OpenFileSearchPageAction implements IWorkbenchWindowActionDelegate { - - private static final String TEXT_SEARCH_PAGE_ID= "org.eclipse.search.internal.ui.text.TextSearchPage"; //$NON-NLS-1$ - - private IWorkbenchWindow fWindow; - - public OpenFileSearchPageAction() { - } - - public void init(IWorkbenchWindow window) { - fWindow= window; - } - - public void run(IAction action) { - if (fWindow == null || fWindow.getActivePage() == null) { - SearchPlugin.beep(); - logErrorMessage("Could not open the search dialog - for some reason the window handle was null"); //$NON-NLS-1$ - return; - } - SearchUI.openSearchDialog(fWindow, TEXT_SEARCH_PAGE_ID); //$NON-NLS-1$ - } - - public void selectionChanged(IAction action, ISelection selection) { - // do nothing since the action isn't selection dependent. - } - - public void dispose() { - fWindow= null; - } - - public static void logErrorMessage(String message) { - IStatus status= new Status(IStatus.ERROR, SearchUI.PLUGIN_ID, IStatus.ERROR, message, null); - SearchPlugin.getDefault().log(status); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogAction.java deleted file mode 100644 index 76c91979a8d..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; - -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; - -/** - * Opens the Search Dialog. - */ -public class OpenSearchDialogAction extends Action implements IWorkbenchWindowActionDelegate { - - private IWorkbenchWindow fWindow; - private String fPageId; - - public OpenSearchDialogAction() { - super(SearchMessages.getString("OpenSearchDialogAction.label")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_TOOL, SearchPluginImages.IMG_TOOL_SEARCH); - setToolTipText(SearchMessages.getString("OpenSearchDialogAction.tooltip")); //$NON-NLS-1$ - } - - public OpenSearchDialogAction(IWorkbenchWindow window, String pageId) { - this(); - fPageId= pageId; - fWindow= window; - } - - public void init(IWorkbenchWindow window) { - fWindow= window; - } - - public void run(IAction action) { - run(); - } - - public void run() { - if (getWindow().getActivePage() == null) { - SearchPlugin.beep(); - return; - } - SearchDialog dialog= new SearchDialog( - getWindow().getShell(), - SearchPlugin.getWorkspace(), - getSelection(), - getEditorPart(), - fPageId); - dialog.open(); - } - - public void selectionChanged(IAction action, ISelection selection) { - // do nothing since the action isn't selection dependent. - } - - private ISelection getSelection() { - return getWindow().getSelectionService().getSelection(); - } - - private IEditorPart getEditorPart() { - return getWindow().getActivePage().getActiveEditor(); - } - - private IWorkbenchWindow getWindow() { - if (fWindow == null) - fWindow= SearchPlugin.getActiveWorkbenchWindow(); - return fWindow; - } - - public void dispose() { - fWindow= null; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllResultsAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllResultsAction.java deleted file mode 100644 index 03985bb26e4..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllResultsAction.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; -import org.eclipse.search.ui.SearchUI; - -class RemoveAllResultsAction extends Action { - - public RemoveAllResultsAction() { - super(SearchMessages.getString("SearchResultView.removeAllResults.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SearchResultView.removeAllResults.tooltip")); //$NON-NLS-1$ - } - - public void run() { - try { - SearchPlugin.getWorkspace().getRoot().deleteMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllSearchesAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllSearchesAction.java deleted file mode 100644 index cd3ae3b5ae7..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveAllSearchesAction.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -class RemoveAllSearchesAction extends Action { - - public RemoveAllSearchesAction() { - super(SearchMessages.getString("SearchResultView.removeAllSearches.text")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_REM_ALL); - setToolTipText(SearchMessages.getString("SearchResultView.removeAllSearches.tooltip")); //$NON-NLS-1$ - } - - public void run() { - SearchManager.getDefault().removeAllSearches(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveMatchAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveMatchAction.java deleted file mode 100644 index f91fc047008..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveMatchAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; - -import org.eclipse.search.ui.ISearchResultViewEntry; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -class RemoveMatchAction extends Action { - - private ISelectionProvider fSelectionProvider; - - public RemoveMatchAction(ISelectionProvider provider) { - super(SearchMessages.getString("SearchResultView.removeMatch.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SearchResultView.removeMatch.tooltip")); //$NON-NLS-1$ - fSelectionProvider= provider; - } - - public void run() { - IMarker[] markers= getMarkers(fSelectionProvider.getSelection()); - if (markers != null) - try { - SearchPlugin.getWorkspace().deleteMarkers(markers); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - } - - private IMarker[] getMarkers(ISelection s) { - if (! (s instanceof IStructuredSelection) || s.isEmpty()) - return null; - - IStructuredSelection selection= (IStructuredSelection)s; - int size= selection.size(); - if (size != 1) - return null; - if (selection.getFirstElement() instanceof ISearchResultViewEntry) { - IMarker marker= ((ISearchResultViewEntry)selection.getFirstElement()).getSelectedMarker(); - if (marker != null) - return new IMarker[] {marker}; - } - return null; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java deleted file mode 100644 index 14d8109f6bb..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.MessageDialog; - -import org.eclipse.ui.IWorkbenchSite; - -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -class RemovePotentialMatchesAction extends Action { - - IWorkbenchSite fSite; - - public RemovePotentialMatchesAction(IWorkbenchSite site) { - super(SearchMessages.getString("RemovePotentialMatchesAction.removePotentialMatches.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("RemovePotentialMatchesAction.removePotentialMatches.tooltip")); //$NON-NLS-1$ - fSite= site; - } - - public void run() { - IMarker[] markers= getMarkers(); - if (markers != null) - try { - SearchPlugin.getWorkspace().deleteMarkers(markers); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - else { - String title= SearchMessages.getString("RemovePotentialMatchesAction.dialog.title"); //$NON-NLS-1$ - String message= SearchMessages.getString("RemovePotentialMatchesAction.dialog.message"); //$NON-NLS-1$ - MessageDialog.openInformation(fSite.getShell(), title, message); - } - - // action only makes sense once - setEnabled(false); - } - - private IMarker[] getMarkers() { - IMarker[] markers; - try { - markers= SearchPlugin.getWorkspace().getRoot().findMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.findMarkers.title"), SearchMessages.getString("Search.Error.findMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return null; - } - - ArrayList potentialMatches= new ArrayList(markers.length); - for (int i= 0; i < markers.length; i++) { - if (markers[i].getAttribute(SearchUI.POTENTIAL_MATCH, false)) - potentialMatches.add(markers[i]); - } - if (potentialMatches.size() == 0) - return null; - - return (IMarker[])potentialMatches.toArray(new IMarker[potentialMatches.size()]); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java deleted file mode 100644 index 6c00310d3f3..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; - -import org.eclipse.swt.custom.BusyIndicator; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; - -import org.eclipse.search.ui.ISearchResultViewEntry; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -class RemoveResultAction extends Action { - - private ISelectionProvider fSelectionProvider; - - public RemoveResultAction(ISelectionProvider provider, boolean stringsDependOnMatchCount) { - fSelectionProvider= provider; - if (!stringsDependOnMatchCount || usePluralLabel()) { - setText(SearchMessages.getString("SearchResultView.removeEntries.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SearchResultView.removeEntries.tooltip")); //$NON-NLS-1$ - } - else { - setText(SearchMessages.getString("SearchResultView.removeEntry.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SearchResultView.removeEntry.tooltip")); //$NON-NLS-1$ - } - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_REM); - } - - public void run() { - final IMarker[] markers= getMarkers(fSelectionProvider.getSelection()); - if (markers != null) { - BusyIndicator.showWhile(SearchPlugin.getActiveWorkbenchShell().getDisplay(), new Runnable() { - public void run() { - try { - SearchPlugin.getWorkspace().deleteMarkers(markers); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - } - }); - } - } - - private IMarker[] getMarkers(ISelection s) { - if (! (s instanceof IStructuredSelection) || s.isEmpty()) - return null; - - IStructuredSelection selection= (IStructuredSelection)s; - int size= selection.size(); - if (size <= 0) - return null; - ArrayList markers= new ArrayList(size * 3); - int markerCount= 0; - Iterator iter= selection.iterator(); - for(int i= 0; iter.hasNext(); i++) { - SearchResultViewEntry entry= (SearchResultViewEntry)iter.next(); - markerCount += entry.getMatchCount(); - markers.addAll(entry.getMarkers()); - } - return (IMarker[])markers.toArray(new IMarker[markerCount]); - } - - private boolean usePluralLabel() { - ISelection s= fSelectionProvider.getSelection(); - if (s == null || s.isEmpty() || !(s instanceof IStructuredSelection)) - return false; - IStructuredSelection selection= (IStructuredSelection)s; - - if (selection.size() != 1) - return true; - - Object firstElement= selection.getFirstElement(); - if (firstElement instanceof ISearchResultViewEntry) - return ((ISearchResultViewEntry)firstElement).getMatchCount() > 1; - else - return false; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java deleted file mode 100644 index d8911296b90..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Stack; - -import org.eclipse.core.resources.IResource; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Item; - -import org.eclipse.jface.viewers.ContentViewer; -import org.eclipse.jface.viewers.ILabelProvider; - -import org.eclipse.search.ui.ISearchResultViewEntry; - -/** - * Helper class for updating error markers and other decorators that work on resources. - * Items are mapped to their element's underlying resource. - * Method <code>resourceChanged</code> updates all items that are affected from the changed - * elements. - */ -class ResourceToItemsMapper { - - private static final int NUMBER_LIST_REUSE= 10; - - // map from resource to item - private HashMap fResourceToItem; - private Stack fReuseLists; - - private ContentViewer fContentViewer; - - public ResourceToItemsMapper(ContentViewer viewer) { - fResourceToItem= new HashMap(); - fReuseLists= new Stack(); - - fContentViewer= viewer; - } - - /** - * Must be called from the UI thread. - */ - public void resourceChanged(IResource changedResource) { - Object obj= fResourceToItem.get(changedResource); - if (obj == null) { - // not mapped - } else if (obj instanceof Item) { - updateItem((Item) obj); - } else { // List of Items - List list= (List) obj; - for (int k= 0; k < list.size(); k++) { - updateItem((Item) list.get(k)); - } - } - } - - private void updateItem(Item item) { - if (!item.isDisposed()) { // defensive code - ILabelProvider lprovider= (ILabelProvider) fContentViewer.getLabelProvider(); - - Object data= item.getData(); - Image oldImage= item.getImage(); - Image image= lprovider.getImage(data); - if (image != null && !image.equals(oldImage)) { - item.setImage(image); - } - String oldText= item.getText(); - String text= lprovider.getText(data); - if (text != null && !text.equals(oldText)) { - item.setText(text); - } - } - } - - /** - * Adds a new item to the map. - * @param element Element to map - * @param item The item used for the element - */ - public void addToMap(Object element, Item item) { - IResource resource= ((ISearchResultViewEntry)element).getResource(); - if (resource != null) { - Object existingMapping= fResourceToItem.get(resource); - if (existingMapping == null) { - fResourceToItem.put(resource, item); - } else if (existingMapping instanceof Item) { - if (existingMapping != item) { - List list= getNewList(); - list.add(existingMapping); - list.add(item); - fResourceToItem.put(resource, list); - } - } else { // List - List list= (List) existingMapping; - if (!list.contains(item)) { - list.add(item); - } - } - } - } - - /** - * Removes an element from the map. - */ - public void removeFromMap(Object element, Item item) { - IResource resource= ((ISearchResultViewEntry)element).getResource(); - if (resource != null) { - Object existingMapping= fResourceToItem.get(resource); - if (existingMapping == null) { - return; - } else if (existingMapping instanceof Item) { - fResourceToItem.remove(resource); - } else { // List - List list= (List) existingMapping; - list.remove(item); - if (list.isEmpty()) { - fResourceToItem.remove(list); - releaseList(list); - } - } - } - } - - private List getNewList() { - if (!fReuseLists.isEmpty()) { - return (List) fReuseLists.pop(); - } - return new ArrayList(2); - } - - private void releaseList(List list) { - if (fReuseLists.size() < NUMBER_LIST_REUSE) { - fReuseLists.push(list); - } - } - - /** - * Clears the map. - */ - public void clearMap() { - fResourceToItem.clear(); - } - - /** - * Clears the map. - */ - public boolean isEmpty() { - return fResourceToItem.isEmpty(); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java deleted file mode 100644 index 0d357ce3848..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Text; - -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; - -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog; - -import org.eclipse.search.ui.ISearchPageContainer; - -import org.eclipse.search.internal.ui.util.SWTUtil; - -public class ScopePart { - - // The possible scopes - public static final int WORKSPACE_SCOPE= 0; - public static final int SELECTION_SCOPE= 1; - public static final int WORKING_SET_SCOPE= 2; - - // Settings store - private static final String DIALOG_SETTINGS_KEY= "SearchDialog.ScopePart"; //$NON-NLS-1$ - private static final String STORE_LRU_WORKING_SET_NAME= "lastUsedWorkingSetName"; //$NON-NLS-1$ - private static final String STORE_LRU_WORKING_SET_NAMES= "lastUsedWorkingSetNames"; //$NON-NLS-1$ - private static IDialogSettings fgSettingsStore; - - private Group fPart; - - // Scope radio buttons - private Button fUseWorkspace; - private Button fUseSelection; - private Button fUseWorkingSet; - - - private int fScope; - private Text fWorkingSetText; - private IWorkingSet[] fWorkingSets; - - // Reference to its search page container (can be null) - private ISearchPageContainer fSearchPageContainer; - - /** - * Returns a new scope part with workspace as initial scope. - * The part is not yet created. - */ - public ScopePart() { - this(WORKSPACE_SCOPE); - } - - /** - * Returns a new scope part with workspace as initial scope. - * The part is not yet created. - */ - public ScopePart(ISearchPageContainer searchPageContainer) { - this(WORKSPACE_SCOPE); - fSearchPageContainer= searchPageContainer; - } - - /** - * Returns a new scope part with an initial scope. - * The part is not yet created. - * - * @see #createPart(Composite) - * @param initialScope the initial scope - */ - public ScopePart(int initialScope) { - Assert.isLegal(initialScope >= 0 && initialScope <= 3); - fScope= initialScope; - restoreState(); - } - - private void restoreState() { - fgSettingsStore= SearchPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS_KEY); - if (fgSettingsStore == null) - fgSettingsStore= SearchPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS_KEY); - String[] lruWorkingSetNames= fgSettingsStore.getArray(STORE_LRU_WORKING_SET_NAMES); - if (lruWorkingSetNames != null) { - Set existingWorkingSets= new HashSet(lruWorkingSetNames.length); - for (int i= 0; i < lruWorkingSetNames.length; i++) { - String name= lruWorkingSetNames[i]; - IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(name); - if (workingSet != null) - existingWorkingSets.add(workingSet); - } - if (!existingWorkingSets.isEmpty()) - fWorkingSets= (IWorkingSet[])existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]); - } - else { - // Backward compatibility - String workingSetName= fgSettingsStore.get(STORE_LRU_WORKING_SET_NAME); - if (workingSetName != null) { - IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName); - if (workingSet != null) { - fWorkingSets= new IWorkingSet[] { workingSet }; - saveState(); - } - } - } - } - - /** - * Returns a new scope part with an initial working set. - * The part is not yet created. - * - * @see #createPart(Composite) - * @param workingSet the initial working set - */ - public ScopePart(IWorkingSet[] workingSets) { - Assert.isNotNull(workingSets); - fScope= WORKING_SET_SCOPE; - fWorkingSets= workingSets; - } - - /** - * Returns the scope selected in this part - * - * @return the selected scope - */ - public int getSelectedScope() { - return fScope; - } - - /** - * Sets the selected scope. - * This method must only be called on a created part. - * - * @param scope the scope to be selected in this part - */ - public void setSelectedScope(int scope) { - Assert.isLegal(scope >= 0 && scope <= 3); - Assert.isNotNull(fUseWorkspace); - Assert.isNotNull(fUseSelection); - Assert.isNotNull(fUseWorkingSet); - fScope= scope; - switch (fScope) { - case WORKSPACE_SCOPE: - fUseWorkspace.setSelection(true); - fUseSelection.setSelection(false); - fUseWorkingSet.setSelection(false); - break; - case SELECTION_SCOPE: - fUseWorkspace.setSelection(false); - fUseSelection.setSelection(true); - fUseWorkingSet.setSelection(false); - break; - case WORKING_SET_SCOPE: - fUseWorkspace.setSelection(false); - fUseSelection.setSelection(false); - fUseWorkingSet.setSelection(true); - break; - } - - updateSearchPageContainerActionPerformedEnablement(); - } - - private void updateSearchPageContainerActionPerformedEnablement() { - boolean newState= fScope != WORKING_SET_SCOPE || fWorkingSets != null; - if (fSearchPageContainer instanceof SearchDialog) - ((SearchDialog)fSearchPageContainer).setPerformActionEnabledFromScopePart(newState); - else if (fSearchPageContainer != null) - fSearchPageContainer.setPerformActionEnabled(newState); - } - - /** - * Returns the selected working set of this part. - * - * @return the selected working set or null - * - if the scope is not WORKING_SET_SCOPE - * - if there is no working set selected - */ - public IWorkingSet[] getSelectedWorkingSets() { - if (getSelectedScope() == WORKING_SET_SCOPE) - return fWorkingSets; - else - return null; - } - - /** - * Sets the selected working set for this part. - * This method must only be called on a created part. - * - * @param workingSet the working set to be selected - */ - public void setSelectedWorkingSets(IWorkingSet[] workingSets) { - Assert.isNotNull(workingSets); - setSelectedScope(WORKING_SET_SCOPE); - fWorkingSets= null; - Set existingWorkingSets= new HashSet(workingSets.length); - for (int i= 0; i < workingSets.length; i++) { - String name= workingSets[i].getName(); - IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(name); - if (workingSet != null) - existingWorkingSets.add(workingSet); - } - if (!existingWorkingSets.isEmpty()) - fWorkingSets= (IWorkingSet[])existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]); - - saveState(); - - if (fWorkingSetText != null) - fWorkingSetText.setText(toString(fWorkingSets)); - } - - /** - * Saves the last recently used working sets, - * if any. - */ - private void saveState() { - if (fWorkingSets != null && fWorkingSets.length > 0) { - String[] existingWorkingSetNames= new String[fWorkingSets.length]; - for (int i= 0; i < existingWorkingSetNames.length; i++) - existingWorkingSetNames[i]= fWorkingSets[i].getName(); - fgSettingsStore.put(STORE_LRU_WORKING_SET_NAMES, existingWorkingSetNames); - } - } - - /** - * Creates this scope part. - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - */ - public Composite createPart(Composite parent) { - fPart= new Group(parent, SWT.NONE); - fPart.setText(SearchMessages.getString("ScopePart.group.text")); //$NON-NLS-1$ - - GridLayout layout= new GridLayout(); - layout.numColumns= 3; - fPart.setLayout(layout); - fPart.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - fUseWorkspace= new Button(fPart, SWT.RADIO); - fUseWorkspace.setData(new Integer(WORKSPACE_SCOPE)); - fUseWorkspace.setText(SearchMessages.getString("ScopePart.workspaceScope.text")); //$NON-NLS-1$ - - fUseSelection= new Button(fPart, SWT.RADIO); - fUseSelection.setData(new Integer(SELECTION_SCOPE)); - fUseSelection.setText(SearchMessages.getString("ScopePart.selectedResourcesScope.text")); //$NON-NLS-1$ - ISelection selection= fSearchPageContainer.getSelection(); - fUseSelection.setEnabled(selection instanceof IStructuredSelection && !fSearchPageContainer.getSelection().isEmpty()); - - GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - gd.horizontalSpan= 2; - gd.horizontalIndent= 8; - fUseSelection.setLayoutData(gd); - - fUseWorkingSet= new Button(fPart, SWT.RADIO); - fUseWorkingSet.setData(new Integer(WORKING_SET_SCOPE)); - fUseWorkingSet.setText(SearchMessages.getString("ScopePart.workingSetScope.text")); //$NON-NLS-1$ - fWorkingSetText= new Text(fPart, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY); - Button chooseWorkingSet= new Button(fPart, SWT.PUSH); - chooseWorkingSet.setLayoutData(new GridData()); - chooseWorkingSet.setText(SearchMessages.getString("ScopePart.workingSetChooseButton.text")); //$NON-NLS-1$ - SWTUtil.setButtonDimensionHint(chooseWorkingSet); - chooseWorkingSet.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (handleChooseWorkingSet()) { - setSelectedScope(WORKING_SET_SCOPE); - } - } - }); - gd= new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalIndent= 8; - gd.widthHint= SWTUtil.convertWidthInCharsToPixels(30, fWorkingSetText); - fWorkingSetText.setLayoutData(gd); - - // Add scope change listeners - SelectionAdapter scopeChangedLister= new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleScopeChanged(e); - } - }; - fUseWorkspace.addSelectionListener(scopeChangedLister); - fUseSelection.addSelectionListener(scopeChangedLister); - fUseWorkingSet.addSelectionListener(scopeChangedLister); - - // Set initial scope - setSelectedScope(fScope); - - // Set initial working set - if (fWorkingSets != null) - fWorkingSetText.setText(toString(fWorkingSets)); - - return fPart; - } - - private void handleScopeChanged(SelectionEvent e) { - Object source= e.getSource(); - if (source instanceof Button) { - Button button= (Button)source; - if (button.getSelection()) - setSelectedScope(((Integer)button.getData()).intValue()); - } - } - - private boolean handleChooseWorkingSet() { - IWorkingSetSelectionDialog dialog= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSetSelectionDialog(fUseSelection.getShell(), true); - - if (fWorkingSets != null) - dialog.setSelection(fWorkingSets); - if (dialog.open() == Window.OK) { - Object[] result= dialog.getSelection(); - if (result.length > 0) { - setSelectedWorkingSets((IWorkingSet[])result); - return true; - } - fWorkingSetText.setText(""); //$NON-NLS-1$ - fWorkingSets= null; - if (fScope == WORKING_SET_SCOPE) - setSelectedScope(WORKSPACE_SCOPE); - return false; - } else { - // test if selected working set has been removed - if (!Arrays.asList(PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets()).contains(fWorkingSets)) { - fWorkingSetText.setText(""); //$NON-NLS-1$ - fWorkingSets= null; - updateSearchPageContainerActionPerformedEnablement(); - } - } - return false; - } - - void setVisible(boolean state) { - fPart.setVisible(state); - } - - public static String toString(IWorkingSet[] workingSets) { - String result= ""; //$NON-NLS-1$ - if (workingSets != null && workingSets.length > 0) { - Arrays.sort(workingSets, new WorkingSetComparator()); - boolean firstFound= false; - for (int i= 0; i < workingSets.length; i++) { - String workingSetName= workingSets[i].getName(); - if (firstFound) - result= SearchMessages.getFormattedString("ScopePart.workingSetConcatenation", new String[] {result, workingSetName}); //$NON-NLS-1$ - else { - result= workingSetName; - firstFound= true; - } - } - } - return result; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java deleted file mode 100644 index bd5eaf880f2..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IWorkspaceDescription; - -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; - -import org.eclipse.search.ui.IActionGroupFactory; -import org.eclipse.search.ui.IContextMenuContributor; -import org.eclipse.search.ui.IGroupByKeyComputer; -import org.eclipse.search.ui.ISearchResultViewEntry; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -public class Search extends Object { - private String fPageId; - private String fSingularLabel; - private String fPluralLabelPattern; - private ImageDescriptor fImageDescriptor; - private ILabelProvider fLabelProvider; - private ISelection fSelection; - private ArrayList fResults; - private IAction fGotoMarkerAction; - private IContextMenuContributor fContextMenuContributor; - private IActionGroupFactory fActionGroupFactory; - private IGroupByKeyComputer fGroupByKeyComputer; - private IRunnableWithProgress fOperation; - - - public Search(String pageId, String singularLabel, String pluralLabelPattern, ILabelProvider labelProvider, ImageDescriptor imageDescriptor, IAction gotoMarkerAction, IActionGroupFactory groupFactory, IGroupByKeyComputer groupByKeyComputer, IRunnableWithProgress operation) { - fPageId= pageId; - fSingularLabel= singularLabel; - fPluralLabelPattern= pluralLabelPattern; - fImageDescriptor= imageDescriptor; - fLabelProvider= labelProvider; - fGotoMarkerAction= gotoMarkerAction; - fActionGroupFactory= groupFactory; - fGroupByKeyComputer= groupByKeyComputer; - fOperation= operation; - - if (fPluralLabelPattern == null) - fPluralLabelPattern= ""; //$NON-NLS-1$ - } - - public Search(String pageId, String singularLabel, String pluralLabelPattern, ILabelProvider labelProvider, ImageDescriptor imageDescriptor, IAction gotoMarkerAction, IContextMenuContributor contextMenuContributor, IGroupByKeyComputer groupByKeyComputer, IRunnableWithProgress operation) { - fPageId= pageId; - fSingularLabel= singularLabel; - fPluralLabelPattern= pluralLabelPattern; - fImageDescriptor= imageDescriptor; - fLabelProvider= labelProvider; - fGotoMarkerAction= gotoMarkerAction; - fContextMenuContributor= contextMenuContributor; - fGroupByKeyComputer= groupByKeyComputer; - fOperation= operation; - - if (fPluralLabelPattern == null) - fPluralLabelPattern= ""; //$NON-NLS-1$ - } - - /** - * Returns the full description of the search. - * The description set by the client where - * {0} will be replaced by the match count. - */ - String getFullDescription() { - if (fSingularLabel != null && getItemCount() == 1) - return fSingularLabel; - - // try to replace "{0}" with the match count - int i= fPluralLabelPattern.lastIndexOf("{0}"); //$NON-NLS-1$ - if (i < 0) - return fPluralLabelPattern; - else - return fPluralLabelPattern.substring(0, i) + getItemCount()+ fPluralLabelPattern.substring(Math.min(i + 3, fPluralLabelPattern.length())); - } - - /** - * Returns a short description of the search. - * Cuts off after 30 characters and adds ... - * The description set by the client where - * {0} will be replaced by the match count. - */ - String getShortDescription() { - String text= getFullDescription(); - int separatorPos= text.indexOf(" - "); //$NON-NLS-1$ - if (separatorPos < 1) - return text.substring(0, Math.min(50, text.length())) + "..."; // use first 50 characters //$NON-NLS-1$ - if (separatorPos < 30) - return text; // don't cut - if (text.charAt(0) == '"') //$NON-NLS-1$ - return text.substring(0, Math.min(30, text.length())) + "...\" - " + text.substring(Math.min(separatorPos + 3, text.length())); //$NON-NLS-1$ - else - return text.substring(0, Math.min(30, text.length())) + "... - " + text.substring(Math.min(separatorPos + 3, text.length())); //$NON-NLS-1$ - } - /** Image used when search is displayed in a list */ - ImageDescriptor getImageDescriptor() { - return fImageDescriptor; - } - - int getItemCount() { - int count= 0; - Iterator iter= getResults().iterator(); - while (iter.hasNext()) - count += ((ISearchResultViewEntry)iter.next()).getMatchCount(); - return count; - } - - List getResults() { - if (fResults == null) - return new ArrayList(); - return fResults; - } - - ILabelProvider getLabelProvider() { - return fLabelProvider; - } - - void searchAgain() { - if (fOperation == null) - return; - Shell shell= SearchPlugin.getActiveWorkbenchShell(); - IWorkspaceDescription workspaceDesc= SearchPlugin.getWorkspace().getDescription(); - boolean isAutoBuilding= workspaceDesc.isAutoBuilding(); - if (isAutoBuilding) - // disable auto-build during search operation - SearchPlugin.setAutoBuilding(false); - try { - new ProgressMonitorDialog(shell).run(true, true, fOperation); - } catch (InvocationTargetException ex) { - ExceptionHandler.handle(ex, shell, SearchMessages.getString("Search.Error.search.title"), SearchMessages.getString("Search.Error.search.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } catch(InterruptedException e) { - } finally { - if (isAutoBuilding) - // enable auto-building again - SearchPlugin.setAutoBuilding(true); - } - } - - boolean isSameSearch(Search search) { - return search != null && search.getOperation() == fOperation; - } - - void backupMarkers() { - Iterator iter= getResults().iterator(); - while (iter.hasNext()) { - ((SearchResultViewEntry)iter.next()).backupMarkers(); - } - } - - String getPageId() { - return fPageId; - } - - IGroupByKeyComputer getGroupByKeyComputer() { - return fGroupByKeyComputer; - } - - public IRunnableWithProgress getOperation() { - return fOperation; - } - - IAction getGotoMarkerAction() { - return fGotoMarkerAction; - } - - /* - * XXX: Activate deprecate tag after 2.0 - * @deprecated As of build > 20020514 use #getActionGroupFactory - */ - IContextMenuContributor getContextMenuContributor() { - return fContextMenuContributor; - } - - IActionGroupFactory getActionGroupFactory() { - return fActionGroupFactory; - } - - public void removeResults() { - fResults= null; - } - - void setResults(ArrayList results) { - Assert.isNotNull(results); - fResults= results; - } - - ISelection getSelection() { - return fSelection; - } - - void setSelection(ISelection selection) { - fSelection= selection; - } -} - diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchAgainAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchAgainAction.java deleted file mode 100644 index 47d0c65161c..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchAgainAction.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -class SearchAgainAction extends Action { - - public SearchAgainAction() { - super(SearchMessages.getString("SearchResultView.searchAgain.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SearchResultView.searchAgain.tooltip")); //$NON-NLS-1$ - } - - public void run() { - Search selected= SearchManager.getDefault().getCurrentSearch(); - if (selected != null) - selected.searchAgain(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java deleted file mode 100644 index 011377b3764..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java +++ /dev/null @@ -1,532 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IWorkspace; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -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.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Layout; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.TabFolder; -import org.eclipse.swt.widgets.TabItem; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; - -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.dialogs.ListSelectionDialog; -import org.eclipse.ui.help.WorkbenchHelp; - -import org.eclipse.search.ui.ISearchPage; -import org.eclipse.search.ui.ISearchPageContainer; -import org.eclipse.search.ui.ISearchPageScoreComputer; - -import org.eclipse.search.internal.ui.util.ExtendedDialogWindow; -import org.eclipse.search.internal.ui.util.ListContentProvider; -import org.eclipse.search.internal.ui.util.SWTUtil; - -class SearchDialog extends ExtendedDialogWindow implements ISearchPageContainer { - - - private class TabFolderLayout extends Layout { - protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { - if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) - return new Point(wHint, hHint); - - int x= 0; - int y= 0; - Control[] children= composite.getChildren(); - for (int i= 0; i < children.length; i++) { - Point size= children[i].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache); - x= Math.max(x, size.x); - y= Math.max(y, size.y); - } - - Point minSize= getMinSize(); - x= Math.max(x, minSize.x); - y= Math.max(y, minSize.y); - - if (wHint != SWT.DEFAULT) - x= wHint; - if (hHint != SWT.DEFAULT) - y= hHint; - return new Point(x, y); - } - protected void layout(Composite composite, boolean flushCache) { - Rectangle rect= composite.getClientArea(); - - Control[] children= composite.getChildren(); - for (int i= 0; i < children.length; i++) { - children[i].setBounds(rect); - } - } - } - - - private IWorkspace fWorkspace; - private ISearchPage fCurrentPage; - private String fInitialPageId; - private int fCurrentIndex; - private ISelection fSelection; - private IEditorPart fEditorPart; - private List fDescriptors; - private Point fMinSize; - private ScopePart[] fScopeParts; - private boolean fPageStateIgnoringScopePart; - - public SearchDialog(Shell shell, IWorkspace workspace, ISelection selection, IEditorPart editor, String pageId) { - super(shell); - Assert.isNotNull(workspace); - fWorkspace= workspace; - setPerformActionLabel(SearchMessages.getString("SearchDialog.performAction")); //$NON-NLS-1$ - fSelection= selection; - fEditorPart= editor; - fDescriptors= SearchPlugin.getDefault().getEnabledSearchPageDescriptors(pageId); - fInitialPageId= pageId; - } - - /* (non-Javadoc) - * Method declared in Window. - */ - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText(SearchMessages.getString("SearchDialog.title")); //$NON-NLS-1$ - shell.setImage(SearchPluginImages.get(SearchPluginImages.IMG_TOOL_SEARCH)); - WorkbenchHelp.setHelp(shell, ISearchHelpContextIds.SEARCH_DIALOG); - } - - public IWorkspace getWorkspace() { - return fWorkspace; - } - - public ISelection getSelection() { - return fSelection; - } - - public IEditorPart getEditorPart() { - return fEditorPart; - } - - //---- Page Handling ------------------------------------------------------- - - /* - * Overrides method from Window - */ - public void create() { - super.create(); - if (fCurrentPage != null) - fCurrentPage.setVisible(true); - } - - private void handleCustomizePressed() { - List input= SearchPlugin.getDefault().getSearchPageDescriptors(); - final ArrayList createdImages= new ArrayList(input.size()); - ILabelProvider labelProvider= new LabelProvider() { - public String getText(Object element) { - if (element instanceof SearchPageDescriptor) { - String label= ((SearchPageDescriptor)element).getLabel(); - int i= label.indexOf('&'); - while (i >= 0) { - if (i < label.length()) - label= label.substring(0, i) + label.substring(i+1); - else - label.substring(0, i); - i= label.indexOf('&'); - } - return label; - } else - return null; - } - public Image getImage(Object element) { - if (element instanceof SearchPageDescriptor) { - Image image= ((SearchPageDescriptor)element).getImage().createImage(); - if (image != null) - createdImages.add(image); - return image; - } else - return null; - } - }; - - String message= SearchMessages.getString("SearchPageSelectionDialog.message"); //$NON-NLS-1$ - - ListSelectionDialog dialog= new ListSelectionDialog(getShell(), input, new ListContentProvider(), labelProvider, message) { - public void create() { - super.create(); - final CheckboxTableViewer viewer= getViewer(); - final Button okButton= this.getOkButton(); - viewer.addCheckStateListener(new ICheckStateListener() { - public void checkStateChanged(CheckStateChangedEvent event) { - okButton.setEnabled(viewer.getCheckedElements().length > 0); - } - }); - SelectionListener listener = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - okButton.setEnabled(viewer.getCheckedElements().length > 0); - } - }; - this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener); - this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener); - } - }; - dialog.setTitle(SearchMessages.getString("SearchPageSelectionDialog.title")); //$NON-NLS-1$ - dialog.setInitialSelections(SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray()); - if (dialog.open() == dialog.OK) { - SearchPageDescriptor.setEnabled(dialog.getResult()); - Display display= getShell().getDisplay(); - close(); - if (display != null && !display.isDisposed()) { - display.asyncExec( - new Runnable() { - public void run() { - new OpenSearchDialogAction().run(); - } - }); - } - } - destroyImages(createdImages); - } - - private void destroyImages(List images) { - Iterator iter= images.iterator(); - while (iter.hasNext()) { - Image image= (Image)iter.next(); - if (image != null && !image.isDisposed()) - image.dispose(); - } - } - - protected Control createPageArea(Composite parent) { - int numPages= fDescriptors.size(); - fScopeParts= new ScopePart[numPages]; - - if (numPages == 0) { - Label label= new Label(parent, SWT.CENTER | SWT.WRAP); - label.setText(SearchMessages.getString("SearchDialog.noSearchExtension")); //$NON-NLS-1$ - return label; - } - - fCurrentIndex= getPreferredPageIndex(); - - BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { - public void run() { - fCurrentPage= getDescriptorAt(fCurrentIndex).createObject(); - } - }); - - fCurrentPage.setContainer(this); - - if (numPages == 1) - return getControl(fCurrentPage, parent, 0); - else { - Composite border= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.marginWidth= 7; - layout.marginHeight= 7; - border.setLayout(layout); - - TabFolder folder= new TabFolder(border, SWT.NONE); - folder.setLayoutData(new GridData(GridData.FILL_BOTH)); - folder.setLayout(new TabFolderLayout()); - - for (int i= 0; i < numPages; i++) { - SearchPageDescriptor descriptor= (SearchPageDescriptor)fDescriptors.get(i); - - final TabItem item= new TabItem(folder, SWT.NONE); - item.setText(descriptor.getLabel()); - item.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - item.setData(null); - if (item.getImage() != null) - item.getImage().dispose(); - } - }); - ImageDescriptor imageDesc= descriptor.getImage(); - if (imageDesc != null) - item.setImage(imageDesc.createImage()); - item.setData(descriptor); - if (i == fCurrentIndex) { - item.setControl(getControl(fCurrentPage, folder, i)); - item.setData(fCurrentPage); - } - } - - folder.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - turnToPage(event); - } - }); - - folder.setSelection(fCurrentIndex); - - return border; - } - } - - protected Control createButtonBar(Composite parent) { - Composite composite= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 3; - layout.marginHeight= 0; - layout.marginWidth= 0; - - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Button button= new Button(composite, SWT.NONE); - button.setText(SearchMessages.getString("SearchDialog.customize")); //$NON-NLS-1$ - GridData gd= new GridData(); - gd.horizontalIndent= 2 * new GridLayout().marginWidth; - button.setLayoutData(gd); - SWTUtil.setButtonDimensionHint(button); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleCustomizePressed(); - } - }); - - Label filler= new Label(composite, SWT.NONE); - filler.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - - Control result= super.createButtonBar(composite); - getButton(IDialogConstants.FINISH_ID).setEnabled(fDescriptors.size() > 0); - return result; - } - - protected boolean performAction() { - if (fCurrentPage == null) - return true; - - boolean isAutoBuilding= SearchPlugin.getWorkspace().isAutoBuilding(); - if (isAutoBuilding) - // disable auto-build during search operation - SearchPlugin.setAutoBuilding(false); - try { - return fCurrentPage.performAction(); - } finally { - if (isAutoBuilding) - // enable auto-building again - SearchPlugin.setAutoBuilding(true); - } - } - - private SearchPageDescriptor getDescriptorAt(int index) { - return (SearchPageDescriptor)fDescriptors.get(index); - } - - private Point getMinSize() { - if (fMinSize != null) - return fMinSize; - - int x= 0; - int y= 0; - int length= fDescriptors.size(); - for (int i= 0; i < length; i++) { - Point size= getDescriptorAt(i).getPreferredSize(); - if (size.x != SWT.DEFAULT) - x= Math.max(x, size.x); - if (size.y != SWT.DEFAULT) - y= Math.max(y, size.y); - } - - fMinSize= new Point(x, y); - return fMinSize; - } - - private void turnToPage(SelectionEvent event) { - final TabItem item= (TabItem)event.item; - if (item.getControl() == null) { - final SearchPageDescriptor descriptor= (SearchPageDescriptor)item.getData(); - - BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { - public void run() { - item.setData(descriptor.createObject()); - } - }); - - ISearchPage page= (ISearchPage)item.getData(); - page.setContainer(this); - - Control newControl= getControl(page, (Composite)event.widget, item.getParent().getSelectionIndex()); - item.setControl(newControl); - } - if (item.getData() instanceof ISearchPage) { - fCurrentPage= (ISearchPage)item.getData(); - fCurrentIndex= item.getParent().getSelectionIndex(); - resizeDialogIfNeeded(item.getControl()); - fCurrentPage.setVisible(true); - } - } - - private int getPreferredPageIndex() { - Object element= null; - if (fSelection instanceof IStructuredSelection) - element= ((IStructuredSelection)fSelection).getFirstElement(); - if (element == null && fEditorPart != null) { - element= fEditorPart.getEditorInput(); - if (element instanceof IFileEditorInput) - element= ((IFileEditorInput)element).getFile(); - } - int result= 0; - int level= ISearchPageScoreComputer.LOWEST; - int size= fDescriptors.size(); - for (int i= 0; i < size; i++) { - SearchPageDescriptor descriptor= (SearchPageDescriptor)fDescriptors.get(i); - if (fInitialPageId != null && fInitialPageId.equals(descriptor.getId())) - return i; - - int newLevel= descriptor.computeScore(element); - if ( newLevel > level) { - level= newLevel; - result= i; - } - } - return result; - } - - /* - * Implements method from ISearchPageContainer - */ - public IRunnableContext getRunnableContext() { - return this; - } - - /* - * Implements method from ISearchPageContainer - */ - public int getSelectedScope() { - if (fScopeParts[fCurrentIndex] == null) - // safe code - should not happen - return ScopePart.WORKSPACE_SCOPE; - else - return fScopeParts[fCurrentIndex].getSelectedScope(); - } - - /* - * Implements method from ISearchPageContainer - */ - public IWorkingSet[] getSelectedWorkingSets() { - if (fScopeParts[fCurrentIndex] == null) - // safe code - should not happen - return null; - else - return fScopeParts[fCurrentIndex].getSelectedWorkingSets(); - } - - /* - * Implements method from ISearchPageContainer - */ - public void setSelectedScope(int scope) { - if (fScopeParts[fCurrentIndex] != null) - fScopeParts[fCurrentIndex].setSelectedScope(scope); - } - - /* - * Implements method from ISearchPageContainer - */ - public boolean hasValidScope() { - return getSelectedScope() != WORKING_SET_SCOPE || getSelectedWorkingSets() != null; - } - - /* - * Implements method from ISearchPageContainer - */ - public void setSelectedWorkingSets(IWorkingSet[] workingSets) { - if (fScopeParts[fCurrentIndex] != null) - fScopeParts[fCurrentIndex].setSelectedWorkingSets(workingSets); - } - - /* - * Overrides method from ExtendedDialogWindow - */ - public void setPerformActionEnabled(boolean state) { - super.setPerformActionEnabled(state); - fPageStateIgnoringScopePart= state; - setPerformActionEnabledFromScopePart(hasValidScope()); - } - - /** - * Set the enable state of the perform action button. - * <p> - * Note: This is a special method to be called only from the ScopePart - * </p> - */ - public void setPerformActionEnabledFromScopePart(boolean state) { - if (fPageStateIgnoringScopePart) - super.setPerformActionEnabled(state); - } - - private Control getControl(ISearchPage page, Composite parent, int index) { - if (page.getControl() == null) { - // Page wrapper - Composite pageWrapper= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - pageWrapper.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - layout.marginWidth= 0; - layout.marginHeight= 0; - pageWrapper.setLayout(layout); - - // The page itself - page.createControl(pageWrapper); - - // Search scope - boolean showScope= getDescriptorAt(index).showScopeSection(); - if (showScope) { - Composite c= new Composite(pageWrapper, SWT.NONE); - layout= new GridLayout(); - c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - c.setLayout(layout); - fScopeParts[index]= new ScopePart(this); - fScopeParts[index].createPart(c); - fScopeParts[index].setVisible(true); - } - } - return page.getControl().getParent(); - } - - private void resizeDialogIfNeeded(Control newControl) { - Point currentSize= fCurrentPage.getControl().getSize(); - Point newSize= newControl.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); - if (mustResize(currentSize, newSize)) { - Shell shell= getShell(); - shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true)); - } - } - - private boolean mustResize(Point currentSize, Point newSize) { - return currentSize.x < newSize.x || currentSize.y < newSize.y; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java deleted file mode 100644 index b877e9ff9f5..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.Iterator; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IMenuCreator; - -class SearchDropDownAction extends Action implements IMenuCreator { - - - public static final int RESULTS_IN_DROP_DOWN= 10; - - private SearchResultViewer fViewer; - - public SearchDropDownAction(SearchResultViewer viewer) { - fViewer= viewer; - setText(SearchMessages.getString("SearchResultView.previousSearches.text")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SearchResultView.previousSearches.tooltip")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_HISTORY); - setMenuCreator(this); - } - - public void dispose() { - fViewer= null; - } - - public Menu getMenu(Menu parent) { - return null; - } - - public Menu getMenu(Control parent) { - Menu menu= new Menu(parent); - boolean checkedOne= false; - Iterator iter= SearchManager.getDefault().getPreviousSearches().iterator(); - Search selected= SearchManager.getDefault().getCurrentSearch(); - int i= 0; - while (iter.hasNext() && i++ < RESULTS_IN_DROP_DOWN) { - Search search= (Search)iter.next(); - ShowSearchAction action= new ShowSearchAction(search); - action.setChecked(search.equals(selected)); - if (search.equals(selected)) - checkedOne= true; - addActionToMenu(menu, action); - } - new MenuItem(menu, SWT.SEPARATOR); - if (iter.hasNext()) { - Action others= new ShowSearchesAction(); - others.setChecked(!checkedOne); - addActionToMenu(menu, others); - } - addActionToMenu(menu, new RemoveAllSearchesAction()); - return menu; - } - - protected void addActionToMenu(Menu parent, Action action) { - ActionContributionItem item= new ActionContributionItem(action); - item.fill(parent, -1); - } - - public void run() { - new ShowSearchesAction().run(true); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java deleted file mode 100644 index efdf8269871..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java +++ /dev/null @@ -1,510 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.Viewer; - -import org.eclipse.ui.actions.WorkspaceModifyOperation; - -import org.eclipse.search.ui.IGroupByKeyComputer; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -/** - * Manage search results - */ -public class SearchManager implements IResourceChangeListener { - - static final SearchManager fgDefault= new SearchManager(); - - Search fCurrentSearch= null; - - private SearchManager() { - SearchPlugin.getWorkspace().addResourceChangeListener(this); - } - - private HashSet fListeners= new HashSet(); - private LinkedList fPreviousSearches= new LinkedList(); - private boolean fIsNewSearch= false; - - public static SearchManager getDefault() { - return fgDefault; - } - - /** - * Returns the list with previous searches (ISearch). - */ - LinkedList getPreviousSearches() { - return fPreviousSearches; - } - /** - * Returns the list with current (last) results - */ - ArrayList getCurrentResults() { - if (fCurrentSearch == null) - return new ArrayList(0); - else - return (ArrayList)fCurrentSearch.getResults(); - } - - public Search getCurrentSearch() { - return fCurrentSearch; - } - - void removeAllSearches() { - SearchPlugin.getWorkspace().removeResourceChangeListener(this); - WorkspaceModifyOperation op= new WorkspaceModifyOperation() { - protected void execute(IProgressMonitor monitor) throws CoreException { - monitor.beginTask(SearchMessages.getString("SearchManager.updating"), 100); //$NON-NLS-1$ - SearchPlugin.getWorkspace().getRoot().deleteMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE); - monitor.worked(100); - monitor.done(); - } - }; - boolean isAutoBuilding= SearchPlugin.getWorkspace().isAutoBuilding(); - if (isAutoBuilding) - // disable auto-build during search operation - SearchPlugin.setAutoBuilding(false); - try { - ProgressMonitorDialog dialog= new ProgressMonitorDialog(getShell()); - dialog.run(true, true, op); - } catch (InvocationTargetException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } catch (InterruptedException e) { - // Do nothing. Operation has been canceled. - } finally { - SearchPlugin.getWorkspace().addResourceChangeListener(this); - if (isAutoBuilding) - // enable auto-building again - SearchPlugin.setAutoBuilding(true); - } - - // clear searches - fPreviousSearches= new LinkedList(); - fCurrentSearch= null; - - // update viewers - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) { - SearchResultViewer viewer= (SearchResultViewer)iter.next(); - viewer.setContextMenuTarget(null); - viewer.setActionGroupFactory(null); - viewer.setInput(null); - } - } - - void setCurrentSearch(final Search search) { - if (fCurrentSearch == search) - return; - - SearchPlugin.getWorkspace().removeResourceChangeListener(this); - WorkspaceModifyOperation op= new WorkspaceModifyOperation() { - protected void execute(IProgressMonitor monitor) throws CoreException { - internalSetCurrentSearch(search, monitor); - } - }; - boolean isAutoBuilding= SearchPlugin.getWorkspace().isAutoBuilding(); - if (isAutoBuilding) - // disable auto-build during search operation - SearchPlugin.setAutoBuilding(false); - try { - ProgressMonitorDialog dialog= new ProgressMonitorDialog(getShell()); - dialog.run(true, true, op); - } catch (InvocationTargetException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.switchSearch.title"), SearchMessages.getString("Search.Error.switchSearch.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } catch (InterruptedException e) { - // Do nothing. Operation has been canceled. - } finally { - SearchPlugin.getWorkspace().addResourceChangeListener(this); - if (isAutoBuilding) - // enable auto-building again - SearchPlugin.setAutoBuilding(true); - } - - getPreviousSearches().remove(search); - getPreviousSearches().addFirst(search); - } - - void internalSetCurrentSearch(final Search search, IProgressMonitor monitor) { - if (fCurrentSearch != null) - fCurrentSearch.backupMarkers(); - - final Search previousSearch= fCurrentSearch; - fCurrentSearch= search; - monitor.beginTask(SearchMessages.getString("SearchManager.updating"), getCurrentResults().size() + 20); //$NON-NLS-1$ - - // remove current search markers - try { - SearchPlugin.getWorkspace().getRoot().deleteMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - monitor.worked(10); - - // add search markers - Iterator iter= getCurrentResults().iterator(); - ArrayList emptyEntries= new ArrayList(10); - boolean filesChanged= false; - boolean filesDeleted= false; - IGroupByKeyComputer groupByKeyComputer= getCurrentSearch().getGroupByKeyComputer(); - while (iter.hasNext()) { - monitor.worked(1); - SearchResultViewEntry entry= (SearchResultViewEntry)iter.next(); - Iterator attrPerMarkerIter= entry.getAttributesPerMarker().iterator(); - entry.clearMarkerList(); - if (entry.getResource() == null || !entry.getResource().exists()) { - emptyEntries.add(entry); - filesDeleted= true; - continue; - } - while (attrPerMarkerIter.hasNext()) { - IMarker newMarker= null; - try { - newMarker= entry.getResource().createMarker(SearchUI.SEARCH_MARKER); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.createMarker.title"), SearchMessages.getString("Search.Error.createMarker.message")); //$NON-NLS-2$ //$NON-NLS-1$ - continue; - } - try { - newMarker.setAttributes((Map)attrPerMarkerIter.next()); - if (groupByKeyComputer !=null && groupByKeyComputer.computeGroupByKey(newMarker) == null) { - filesDeleted= true; - newMarker.delete(); - continue; - } - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - entry.add(newMarker); - } - if (entry.getMatchCount() == 0) - emptyEntries.add(entry); - else if (!filesChanged && entry.getResource().getModificationStamp() != entry.getModificationStamp()) - filesChanged= true; - } - getCurrentResults().removeAll(emptyEntries); - monitor.worked(10); - - String warningMessage= null; - Display display= getDisplay(); - - if (filesChanged) - warningMessage= SearchMessages.getString("SearchManager.resourceChanged"); //$NON-NLS-1$ - if (filesDeleted) { - if (warningMessage == null) - warningMessage= ""; //$NON-NLS-1$ - else - warningMessage += "\n"; //$NON-NLS-1$ - warningMessage += SearchMessages.getString("SearchManager.resourceDeleted"); //$NON-NLS-1$ - } - if (warningMessage != null) { - if (display != null && !display.isDisposed()) { - final String warningTitle= SearchMessages.getString("SearchManager.resourceChangedWarning"); //$NON-NLS-1$ - final String warningMsg= warningMessage; - display.syncExec(new Runnable() { - public void run() { - MessageDialog.openWarning(getShell(), warningTitle, warningMsg); - } - }); - } - } - - // update viewers - iter= fListeners.iterator(); - if (display != null && !display.isDisposed()) { - final Viewer visibleViewer= ((SearchResultView)SearchPlugin.getSearchResultView()).getViewer(); - while (iter.hasNext()) { - final SearchResultViewer viewer= (SearchResultViewer)iter.next(); - display.syncExec(new Runnable() { - public void run() { - if (previousSearch != null && viewer == visibleViewer) - previousSearch.setSelection(viewer.getSelection()); - viewer.setInput(null); - viewer.setPageId(search.getPageId()); - viewer.setGotoMarkerAction(search.getGotoMarkerAction()); - viewer.setContextMenuTarget(search.getContextMenuContributor()); - viewer.setActionGroupFactory(null); - viewer.setInput(getCurrentResults()); - viewer.setActionGroupFactory(search.getActionGroupFactory()); - viewer.setSelection(fCurrentSearch.getSelection(), true); - } - }); - } - } - monitor.done(); - } - - /** - * Returns the number of matches - */ - int getCurrentItemCount() { - if (fCurrentSearch != null) - return fCurrentSearch.getItemCount(); - else - return 0; - } - - void addNewSearch(Search newSearch) { - // Clear the viewers - Iterator iter= fListeners.iterator(); - Display display= getDisplay(); - if (display != null && !display.isDisposed()) { - final Viewer visibleViewer= ((SearchResultView)SearchPlugin.getSearchResultView()).getViewer(); - while (iter.hasNext()) { - final SearchResultViewer viewer= (SearchResultViewer)iter.next(); - display.syncExec(new Runnable() { - public void run() { - if (fCurrentSearch != null && viewer == visibleViewer) - fCurrentSearch.setSelection(viewer.getSelection()); - viewer.handleRemoveAll(); - viewer.clearTitle(); - - } - }); - } - } - - if (fCurrentSearch != null) { - if (fCurrentSearch.isSameSearch(newSearch)) - getPreviousSearches().remove(fCurrentSearch); - else - fCurrentSearch.backupMarkers(); - } - fCurrentSearch= newSearch; - getPreviousSearches().addFirst(fCurrentSearch); - - // Remove the markers - try { - SearchPlugin.getWorkspace().getRoot().deleteMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.deleteMarkers.title"), SearchMessages.getString("Search.Error.deleteMarkers.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - } - - void setCurrentResults(ArrayList results) { - Assert.isNotNull(results); - ((Search)getCurrentSearch()).setResults(results); - if (results.isEmpty()) { - // directly update because there will be no delta - Display display= getDisplay(); - if (display == null || display.isDisposed()) - return; - display.syncExec(new Runnable() { - public void run() { - handleNewSearchResult(); - } - }); - } - else - fIsNewSearch= true; - } - - //--- Change event handling ------------------------------------------------- - - void addSearchChangeListener(SearchResultViewer viewer) { - fListeners.add(viewer); - } - - void removeSearchChangeListener(SearchResultViewer viewer) { - Assert.isNotNull(viewer); - fListeners.remove(viewer); - } - - private final void handleSearchMarkersChanged(final IResourceChangeEvent event, IMarkerDelta[] markerDeltas) { - if (fIsNewSearch) { - fIsNewSearch= false; - handleNewSearchResult(); - return; - } - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).getControl().setRedraw(false); - - for (int i=0; i < markerDeltas.length; i++) - handleSearchMarkerChanged(markerDeltas[i]); - - iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).getControl().setRedraw(true); - - } - - private void handleSearchMarkerChanged(IMarkerDelta markerDelta) { - int kind= markerDelta.getKind(); - if ((kind & IResourceDelta.ADDED) != 0) - handleAddMatch(markerDelta.getMarker()); - else if (((kind & IResourceDelta.REMOVED) != 0)) - handleRemoveMatch(markerDelta.getMarker()); - else if ((kind & IResourceDelta.CHANGED) != 0) - handleUpdateMatch(markerDelta.getMarker()); - } - - private void handleRemoveAll() { - if (fCurrentSearch != null) - ((Search)fCurrentSearch).removeResults(); - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleRemoveAll(); - } - - private void handleAddMatch(IMarker marker) { - Object groupByKey= getCurrentSearch().getGroupByKeyComputer().computeGroupByKey(marker); - SearchResultViewEntry entry= findEntry(groupByKey); - if (entry == null) { - entry= new SearchResultViewEntry(groupByKey, marker.getResource()); - getCurrentResults().add(entry); - entry.add(marker); - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleAddMatch(entry); - } - else { - entry.add(marker); - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleUpdateMatch(entry, false); - } - } - - private void handleNewSearchResult() { - Iterator iter= fListeners.iterator(); - final Search search= getCurrentSearch(); - while (iter.hasNext()) { - SearchResultViewer viewer= (SearchResultViewer)iter.next(); - viewer.setPageId(search.getPageId()); - viewer.setGotoMarkerAction(search.getGotoMarkerAction()); - viewer.setContextMenuTarget(search.getContextMenuContributor()); - viewer.setActionGroupFactory(null); - viewer.setInput(getCurrentResults()); - viewer.setActionGroupFactory(search.getActionGroupFactory()); - } - } - - private void handleRemoveMatch(IMarker marker) { - SearchResultViewEntry entry= findEntry(marker); - if (entry != null) { - entry.remove(marker); - if (entry.getMatchCount() == 0) { - getCurrentResults().remove(entry); - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleRemoveMatch(entry); - } - else { - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleUpdateMatch(entry, true); - } - } - } - - private void handleUpdateMatch(IMarker marker) { - SearchResultViewEntry entry= findEntry(marker); - if (entry != null) { - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleUpdateMatch(entry, false); - } - } - - private SearchResultViewEntry findEntry(IMarker marker) { - Iterator entries= getCurrentResults().iterator(); - while (entries.hasNext()) { - SearchResultViewEntry entry= (SearchResultViewEntry)entries.next(); - if (entry.contains(marker)) - return entry; - } - return null; - } - - private SearchResultViewEntry findEntry(Object key) { - if (key == null) - return null; - Iterator entries= getCurrentResults().iterator(); - while (entries.hasNext()) { - SearchResultViewEntry entry= (SearchResultViewEntry)entries.next(); - if (key.equals(entry.getGroupByKey())) - return entry; - } - return null; - } - /** - * Received a resource event. Since the delta could be created in a - * separate thread this methods post the event into the viewer's - * display thread. - */ - public final void resourceChanged(final IResourceChangeEvent event) { - if (event == null) - return; - - final IMarkerDelta[] markerDeltas= event.findMarkerDeltas(SearchUI.SEARCH_MARKER, true); - if (markerDeltas == null || markerDeltas.length < 1) - return; - - Display display= getDisplay(); - if (display == null || display.isDisposed()) - return; - - Runnable runnable= new Runnable() { - public void run() { - handleSearchMarkersChanged(event, markerDeltas); - // update title and actions - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) { - SearchResultViewer viewer= (SearchResultViewer)iter.next(); - viewer.enableActions(); - viewer.updateTitle(); - } - } - }; - display.syncExec(runnable); - } - /** - * Find and return a valid display - */ - private Display getDisplay() { - Iterator iter= fListeners.iterator(); - while (iter.hasNext()) { - Control control= ((Viewer)iter.next()).getControl(); - if (control != null && !control.isDisposed()) { - Display display= control.getDisplay(); - if (display != null && !display.isDisposed()) - return display; - } - } - return null; - } - /** - * Find and return a valid shell - */ - private Shell getShell() { - return SearchPlugin.getActiveWorkbenchShell(); - } -} - diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java deleted file mode 100644 index c0ffc322f6e..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -public class SearchMessages { - - private static final String RESOURCE_BUNDLE= SearchMessages.class.getName(); - - private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); - - private SearchMessages() { - } - - 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 - */ - 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 }); - } - - /** - * 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 - */ - 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.search/search/org/eclipse/search/internal/ui/SearchMessages.properties b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties deleted file mode 100644 index 6acc39581d8..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties +++ /dev/null @@ -1,200 +0,0 @@ -######################################### -# (c) Copyright IBM Corp. 2000, 2002. -# All Rights Reserved. -######################################### - -SearchDialog.title= Search -SearchDialog.performAction= &Search -SearchDialog.customize= Customi&ze... -SearchDialog.noSearchExtension= No Search Extensions plugged into workbench or all search pages disabled. - -SearchPageSelectionDialog.title= Search Page Selection -SearchPageSelectionDialog.message= S&elect the pages which are shown in the dialog: - -SearchManager.resourceChangedWarning= Changed Resources -SearchManager.resourceChanged= Some of the resources have changed. Matches might be at wrong positions. -SearchManager.resourceDeleted= Some of the resources no longer exist. Corresponding matches are removed from the search results. -SearchManager.updating= Updating... - -SearchResultView.title= Search -SearchResultView.titleWithDescription= Search ({0}) -SearchResultView.matches= matches -SearchResultView.removed_resource= <removed resource> -SearchResultView.removeAllResults.text= Remove &All Matches -SearchResultView.removeAllResults.tooltip= Remove All Matches -SearchResultView.removeAllSearches.text= &Clear History -SearchResultView.removeAllSearches.tooltip= Clear the search result history -SearchResultView.searchAgain.text= &Search Again -SearchResultView.searchAgain.tooltip= Search Again -SearchResultView.previousSearches.text= Previous Search Results -SearchResultView.previousSearches.tooltip= Previous Search Results -SearchResultView.removeEntry.text= &Remove Selected Match -SearchResultView.removeEntry.tooltip= Remove Selected Match -SearchResultView.removeEntries.text= &Remove Selected Matches -SearchResultView.removeEntries.tooltip= Remove Selected Matches -SearchResultView.removeMatch.text= Remove Current &Match -SearchResultView.removeMatch.tooltip= Remove Current Match -SearchResultView.gotoMarker.text= &Go to File -SearchResultView.gotoMarker.tooltip= Go to File -SearchResultView.showNext.text= Next Match -SearchResultView.showNext.tooltip= Show Next Match -SearchResultView.showPrev.text= Previous Match -SearchResultView.showPrev.tooltip= Show Previous Match - -SearchDialogClosingDialog.title= Search Dialog Closing -SearchDialogClosingDialog.message= Dialog can not be closed due to an active operation. You must cancel the operation before you can close the dialog. - -Search.Error.search.title= Search Error -Search.Error.search.message= An error occurred during the search operation - -Search.Error.setDescription.title= Search Error -Search.Error.setDescription.message= Can not save workspace description - -Search.Error.openEditor.title= Search Error -Search.Error.openEditor.message= Could not open the editor - -Search.Error.openResultView.title= Search Error -Search.Error.openResultView.message= Could not open the search results view - -Search.Error.deleteMarkers.title= Search Error -Search.Error.deleteMarkers.message= An error occurred during deletion of search markers - -Search.Error.findMarkers.title= Search Error -Search.Error.findMarkers.message= An error occurred while gathering the search markers - -Search.Error.createMarker.title=Search Error -Search.Error.createMarker.message= Could not create the search marker - -Search.Error.markerAttributeAccess.title= Search Error -Search.Error.markerAttributeAccess.message= An error occurred while accessing a marker attribute - -Search.Error.switchSearch.title= Search Error -Search.Error.switchSearch.message= An error occurred while switching to a previous search result - -Search.Error.createSearchPage.title= Search Error -Search.Error.createSearchPage.message= An error occurred while creating a search page - -Search.Error.createSorter.title= Search Error -Search.Error.createSorter.message= An error occurred while creating a sorter - -Search.Error.incorrectIconLocation.message= Invalid icon location - -Search.Problems.title= Text Search Problems - -SearchResultCollector.match= 1 match -SearchResultCollector.matches= {0} matches -SearchResultCollector.done= Search done: {0}. - -SearchPage.containingText.text= C&ontaining text: -SearchPage.containingText.hint= (* = any string, ? = any character, \\ = escape for literals: * ? \\) -SearchPage.browse= &Browse... -SearchPage.fileNamePatterns.text= File name &patterns: -SearchPage.fileNamePatterns.hint= The patterns are separated by comma (* = any string, ? = any character) -SearchPage.caseSensitive= Case sens&itive - -TextSearchEngine.scanning= Scanning file {0} of {1}... -TextSearchEngine.statusMessage= Problems encountered during text search. - -TextSearchVisitor.scanning= Scanning file {0} of {1}... -TextSearchVisitor.error= Error reading file during search: {0} -TextSearchVisitor.canceled= Operation Canceled - -SortDropDownAction.label= S&ort By -SortDropDownAction.tooltip= Sort By - -ShowOtherSearchesAction.label= &Other... -ShowOtherSearchesAction.tooltip= Open Other Searches Dialog - -OtherSearchesDialog.title= Other Searches -OtherSearchesDialog.message= &Select one of the searches - -PreviousSearchesDialog.title= Previous Searches -PreviousSearchesDialog.message= &Select one of the searches - -# The first argument will be replaced by the pattern, the second by the scope -TextSearchOperation.singularLabelPostfix= "{0}" - 1 Occurrence in {1} - -# The argument will be replaced by the scope -FileSearchOperation.singularLabelPostfix= 1 File in {0} - -# The first argument will be replaced by the pattern, the second by the count and the last by the scope -TextSearchOperation.pluralLabelPatternPostfix= "{0}" - {1} Occurrences in {2} - -# The first argument will be replaced by the count and the second by the scope -FileSearchOperation.pluralLabelPatternPostfix= {0} Files in {1} - -OpenSearchDialogAction.label= Search -OpenSearchDialogAction.tooltip= Search - -FileTypeEditor.typeDelimiter= , - -FileLabelProvider.dashSeparated= {0} - {1} - -TypesFiltering.title= Select Types -TypesFiltering.message = S&elect the types to scan. -TypesFiltering.otherExtensions = &Other Patterns: -TypesFiltering.selectAll= &Select All -TypesFiltering.deselectAll= &Deselect All - -WorkspaceScope= Workspace -WorkingSetScope= Working Set - {0} -SelectionScope= Selection - -ScopePart.group.text=Scope -ScopePart.selectedResourcesScope.text=Selecte&d Resources -ScopePart.workingSetChooseButton.text=C&hoose... -ScopePart.workingSetScope.text=Wor&king Set: -ScopePart.workspaceScope.text=&Workspace - -# Concatenate two working set names e.g. "Source, Lib" -ScopePart.workingSetConcatenation= {0}, {1} - -CopyToClipboardAction.label = Copy to Clip&board -CopyToClipboardAction.tooltip = Copy to Clipboard -CopyToClipboardAction.error.title= Problem Copying to Clipboard -CopyToClipboardAction.error.message= There was a problem when accessing the system clipboard. Retry? - -ExceptionDialog.seeErrorLogMessage= See error log for more details - -SearchPreferencePage.emphasizePotentialMatches= &Emphasize inexact matches -SearchPreferencePage.potentialMatchFgColor= &Foreground color for inexact matches: -SearchPreferencePage.reuseEditor= &Reuse editors to show matches -SearchPreferencePage.ignorePotentialMatches= &Ignore inexact matches - -ReplaceAction.label_all= Re&place... -ReplaceAction.label_selected= Rep&lace Selected... -ReplaceAction.error.only_on_text_search= Replace is only available on text search. -ReplaceAction.error.unable_to_perform= Replace operation can\'t be performed. -ReplaceAction.error.changed_file= The content of the following file has changed. Please redo the search to ensure that all matches are correct. -ReplaceAction.error.changed_files= The content of the following files have changed. Please redo the search to ensure that all matches are correct. -ReplaceAction.error.opened_file= The following file is already open in an editor, but the replace operation cannot handle this editor. Please close the editor. -ReplaceAction.error.opened_files= The following files are already open in editors, but the replace operation cannot handle these editors. Please close the editors. -ReplaceAction.error.not_file= The following resource is not a file and cannot be handled. Please exclude it from the replace operation. -ReplaceAction.error.not_files= The following resources are not files and cannot be handled. Please exclude them from the replace operation. -ReplaceAction.dialog.title= Replace - -ReplaceDialog.replace_label= Replace: -ReplaceDialog.with_label= &With: -ReplaceDialog.replace_next= Re&place/Next -ReplaceDialog.replace= &Replace -ReplaceDialog.next= &Next -ReplaceDialog.close= &Close -ReplaceDialog.save_changes=Automatically &save changes -ReplaceDialog.dialog.title= Replace -ReplaceDialog.error.unexpected_exception=Unexpected exception during replace operation. -ReplaceDialog.error.different_content= File content differs from search result. -ReplaceDialog.error.reenable_auto_build_failed=Couldn\'t reactivate auto building. -ReplaceDialog.error.auto_building= Couldn\'t disable auto building. -ReplaceDialog.error.no_matches= Couldn\'t find first match. -ReplaceDialog.error.no_file_for_marker=Current match is not associated with a file. It is not possible to open an editor. -ReplaceDialog.error.unable_to_open_text_editor=It is not possible to open the built-in text editor for file ''{0}''. - -SelectAllAction.label= Select A&ll -SelectAllAction.tooltip= Select All - -RemovePotentialMatchesAction.removePotentialMatches.text= Remove Inexact Matches -RemovePotentialMatchesAction.removePotentialMatches.tooltip= Remove all inexact matches -RemovePotentialMatchesAction.dialog.title= Remove Inexact Matches -RemovePotentialMatchesAction.dialog.message= The current search result does not contain inexact matches. - -OpenWithMenu.label= Open Wit&h
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java deleted file mode 100644 index b913571a35c..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IConfigurationElement; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; - -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.StringConverter; - -import org.eclipse.search.ui.ISearchPage; -import org.eclipse.search.ui.ISearchPageScoreComputer; -import org.eclipse.search.ui.ISearchResultViewEntry; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -/** - * Proxy that represents a search page. - */ -class SearchPageDescriptor implements Comparable { - - public final static String PAGE_TAG= "page"; //$NON-NLS-1$ - private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ - private final static String ICON_ATTRIBUTE= "icon"; //$NON-NLS-1$ - private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$ - private final static String LABEL_ATTRIBUTE= "label"; //$NON-NLS-1$ - private final static String SIZE_ATTRIBUTE= "sizeHint"; //$NON-NLS-1$ - private final static String TAB_POSITION_ATTRIBUTE= "tabPosition"; //$NON-NLS-1$ - private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$ - private final static String SHOW_SCOPE_SECTION_ATTRIBUTE= "showScopeSection"; //$NON-NLS-1$ - private final static String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$ - - public final static Point UNKNOWN_SIZE= new Point(SWT.DEFAULT, SWT.DEFAULT); - - // dialog store id constants - private final static String SECTION_ID= "Search"; //$NON-NLS-1$ - private final static String STORE_ENABLED_PAGE_IDS= SECTION_ID + ".enabledPageIds"; //$NON-NLS-1$ - - private static List fgEnabledPageIds; - - private IConfigurationElement fElement; - - private static class ExtensionScorePair { - public String extension; - public int score; - public ExtensionScorePair(String extension, int score) { - this.extension= extension; - this.score= score; - } - } - private List fExtensionScorePairs; - private int fWildcardScore= ISearchPageScoreComputer.UNKNOWN; - - - - /** - * Creates a new search page node with the given configuration element. - */ - public SearchPageDescriptor(IConfigurationElement element) { - fElement= element; - } - - /** - * Creates a new search page from this node. - */ - public ISearchPage createObject() { - ISearchPage result= null; - try { - result= (ISearchPage)fElement.createExecutableExtension(CLASS_ATTRIBUTE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.createSearchPage.title"), SearchMessages.getString("Search.Error.createSearchPage.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } catch (ClassCastException ex) { - ExceptionHandler.displayMessageDialog(ex, SearchMessages.getString("Search.Error.createSearchPage.title"), SearchMessages.getString("Search.Error.createSearchPage.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return null; - } - if (result != null) { - result.setTitle(getLabel()); - } - return result; - } - - //---- XML Attribute accessors --------------------------------------------- - - /** - * Returns the page's id. - */ - public String getId() { - return fElement.getAttribute(ID_ATTRIBUTE); - } - - /** - * Returns the page's image - */ - public ImageDescriptor getImage() { - String imageName= fElement.getAttribute(ICON_ATTRIBUTE); - if (imageName == null) - return null; - URL url; - try { - url= new URL(fElement.getDeclaringExtension().getDeclaringPluginDescriptor().getInstallURL(), imageName); - } catch (java.net.MalformedURLException ex) { - ExceptionHandler.log(ex, SearchMessages.getString("Search.Error.createSearchPage.message")); //$NON-NLS-1$ - return null; - } - return ImageDescriptor.createFromURL(url); - } - - /** - * Returns the page's label. - */ - public String getLabel() { - return fElement.getAttribute(LABEL_ATTRIBUTE); - } - - /** - * Returns <code>true</code> if the scope section needs - * to be shown in the dialog. - */ - public boolean showScopeSection() { - return Boolean.valueOf(fElement.getAttribute(SHOW_SCOPE_SECTION_ATTRIBUTE)).booleanValue(); - } - - /** - * Returns <code>true</code> if the page is initially - * shown in the Search dialog. - * - * This attribute is optional and defaults to <code>true</code>. - */ - public boolean isInitiallyEnabled() { - String strVal= fElement.getAttribute(ENABLED_ATTRIBUTE); - return strVal == null || Boolean.valueOf(strVal).booleanValue(); - } - - /** - * Returns the page's preferred size - */ - public Point getPreferredSize() { - return StringConverter.asPoint( - fElement.getAttribute(SIZE_ATTRIBUTE), UNKNOWN_SIZE); - } - - /** - * Returns the page's tab position relative to the other tabs. - * @return the tab position or <code>Integer.MAX_VALUE</code> if not defined in - the plugins.xml file - * - */ - public int getTabPosition() { - int position= Integer.MAX_VALUE / 2; - String str= fElement.getAttribute(TAB_POSITION_ATTRIBUTE); - if (str != null) - try { - position= Integer.parseInt(str); - } catch (NumberFormatException ex) { - ExceptionHandler.log(ex, SearchMessages.getString("Search.Error.createSearchPage.message")); //$NON-NLS-1$ - // position is Integer.MAX_VALUE; - } - return position; - } - - boolean isEnabled() { - return getEnabledPageIds().contains(getId()); - } - - static void setEnabled(Object[] enabledDescriptors) { - fgEnabledPageIds= new ArrayList(5); - for (int i= 0; i < enabledDescriptors.length; i++) { - if (enabledDescriptors[i] instanceof SearchPageDescriptor) - fgEnabledPageIds.add(((SearchPageDescriptor)enabledDescriptors[i]).getId()); - } - getDialogSettings().put(STORE_ENABLED_PAGE_IDS, (String[])fgEnabledPageIds.toArray(new String[fgEnabledPageIds.size()])); - } - - private static List getEnabledPageIds() { - if (fgEnabledPageIds == null) { - String[] pageIds= getDialogSettings().getArray(STORE_ENABLED_PAGE_IDS); - if (pageIds == null) { - // Enable all pages - Iterator iter= SearchPlugin.getDefault().getSearchPageDescriptors().iterator(); - List initiallyEnabledDescriptors= new ArrayList(5); - while (iter.hasNext()) { - SearchPageDescriptor desc= (SearchPageDescriptor)iter.next(); - if (desc.isInitiallyEnabled()) - initiallyEnabledDescriptors.add(desc); - } - setEnabled(initiallyEnabledDescriptors.toArray()); - - } else - fgEnabledPageIds= Arrays.asList(pageIds); - } - return fgEnabledPageIds; - } - - private static IDialogSettings getDialogSettings() { - IDialogSettings settings= SearchPlugin.getDefault().getDialogSettings(); - IDialogSettings section= settings.getSection(SECTION_ID); - if (section == null) - // create new section - section= settings.addNewSection(SECTION_ID); - return section; - } - - /* - * Implements a method from IComparable - */ - public int compareTo(Object o) { - int myPos= getTabPosition(); - int objsPos= ((SearchPageDescriptor)o).getTabPosition(); - if (myPos == Integer.MAX_VALUE && objsPos == Integer.MAX_VALUE || myPos == objsPos) - return getLabel().compareTo(((SearchPageDescriptor)o).getLabel()); - else - return myPos - objsPos; - } - - //---- Suitability tests --------------------------------------------------- - - /** - * Returns the score for this page with the given input element. - */ - public int computeScore(Object element) { - if (element instanceof IFile) { - String extension= ((IFile)element).getFileExtension(); - if (extension != null) - return getScoreForFileExtension(extension); - } else if (element instanceof IAdaptable) { - ISearchPageScoreComputer tester= - (ISearchPageScoreComputer)((IAdaptable)element).getAdapter(ISearchPageScoreComputer.class); - if (tester != null) - return tester.computeScore(getId(), element); - } else if (element instanceof ISearchResultViewEntry) { - ISearchResultViewEntry entry= (ISearchResultViewEntry)element; - return computeScore(entry.getSelectedMarker()); - } - if (fWildcardScore != ISearchPageScoreComputer.UNKNOWN) - return fWildcardScore; - - return ISearchPageScoreComputer.LOWEST; - } - - private int getScoreForFileExtension(String extension) { - if (fExtensionScorePairs == null) - readExtensionScorePairs(); - - int size= fExtensionScorePairs.size(); - for (int i= 0; i < size; i++) { - ExtensionScorePair p= (ExtensionScorePair)fExtensionScorePairs.get(i); - if (extension.equals(p.extension)) - return p.score; - } - if (fWildcardScore != ISearchPageScoreComputer.UNKNOWN) - return fWildcardScore; - - return ISearchPageScoreComputer.LOWEST; - } - - private void readExtensionScorePairs() { - fExtensionScorePairs= new ArrayList(3); - String content= fElement.getAttribute(EXTENSIONS_ATTRIBUTE); - if (content == null) - return; - StringTokenizer tokenizer= new StringTokenizer(content, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreElements()) { - String token= tokenizer.nextToken().trim(); - int pos= token.indexOf(':'); - if (pos != -1) { - String extension= token.substring(0, pos); - int score= StringConverter.asInt(token.substring(pos+1), ISearchPageScoreComputer.UNKNOWN); - if (extension.equals("*")) { //$NON-NLS-1$ - fWildcardScore= score; - } else { - fExtensionScorePairs.add(new ExtensionScorePair(extension, score)); - } - } - } - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java deleted file mode 100644 index cfb8681ecbe..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.IPluginRegistry; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; - -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.util.Assert; - -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -import org.eclipse.search.ui.IContextMenuConstants; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -/** - * The plug-in runtime class for Search plug-in - */ -public class SearchPlugin extends AbstractUIPlugin { - - public static final String SEARCH_PAGE_EXTENSION_POINT= "searchPages"; //$NON-NLS-1$ - public static final String SORTER_EXTENSION_POINT= "searchResultSorters"; //$NON-NLS-1$ - - private static SearchPlugin fgSearchPlugin; - - private List fPageDescriptors; - private List fSorterDescriptors; - - private SearchResultViewEntryAdapterFactory fSearchResultViewEntryAdapterFactory; - - public SearchPlugin(IPluginDescriptor descriptor) { - super(descriptor); - Assert.isTrue(fgSearchPlugin == null); - fgSearchPlugin= this; - } - - /** - * Returns the search plugin instance. - */ - public static SearchPlugin getDefault() { - return fgSearchPlugin; - } - - /* - * Overrides AbstractUIPlugin#initializeDefaultPreferences - */ - protected void initializeDefaultPreferences(IPreferenceStore store) { - SearchPreferencePage.initDefaults(store); - } - - /** - * Returns the active workbench window. - * <code>null</code> if the active window is not a workbench window - */ - public static IWorkbenchWindow getActiveWorkbenchWindow() { - IWorkbenchWindow window= fgSearchPlugin.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - final WindowRef windowRef= new WindowRef(); - Display.getDefault().syncExec(new Runnable() { - public void run() { - setActiveWorkbenchWindow(windowRef); - } - }); - return windowRef.window; - } - else - return window; - } - - private static class WindowRef { - public IWorkbenchWindow window; - } - - private static void setActiveWorkbenchWindow(WindowRef windowRef) { - windowRef.window= null; - Display display= Display.getCurrent(); - if (display == null) - return; - Control shell= display.getActiveShell(); - while (shell != null) { - Object data= shell.getData(); - if (data instanceof IWorkbenchWindow) { - windowRef.window= (IWorkbenchWindow)data; - return; - } - shell= shell.getParent(); - } - Shell shells[]= display.getShells(); - for (int i= 0; i < shells.length; i++) { - Object data= shells[i].getData(); - if (data instanceof IWorkbenchWindow) { - windowRef.window= (IWorkbenchWindow)data; - return; - } - } - } - - /** - * Returns the shell of the active workbench window. - */ - public static Shell getActiveWorkbenchShell() { - IWorkbenchWindow window= getActiveWorkbenchWindow(); - if (window != null) - return window.getShell(); - return null; - } - - /** - * Beeps using the display of the active workbench window. - */ - public static void beep() { - getActiveWorkbenchShell().getDisplay().beep(); - } - - /** - * Returns the active workbench window's currrent page. - */ - public static IWorkbenchPage getActivePage() { - return getActiveWorkbenchWindow().getActivePage(); - } - - /** - * Returns the workbench from which this plugin has been loaded. - */ - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - } - - /** - * Activates the search result view in the active page. - * This call has no effect, if the search result view is - * already activated. - * - * @return <code>true</code> if the search result view could be activated - */ - public static boolean activateSearchResultView() { - try { - return (getActivePage().showView(SearchUI.SEARCH_RESULT_VIEW_ID) != null); - } catch (PartInitException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.openResultView.title"), SearchMessages.getString("Search.Error.openResultView.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return false; - } - } - - /** - * Returns the search result view of the active workbench window. Returns <code> - * null</code> if the active workbench window doesn't have any search result - * view. - */ - public static ISearchResultView getSearchResultView() { - IViewPart part= getActivePage().findView(SearchUI.SEARCH_RESULT_VIEW_ID); - if (part instanceof ISearchResultView) - return (ISearchResultView) part; - return null; - } - - static void setAutoBuilding(boolean state) { - IWorkspaceDescription workspaceDesc= getDefault().getWorkspace().getDescription(); - workspaceDesc.setAutoBuilding(state); - try { - getDefault().getWorkspace().setDescription(workspaceDesc); - } - catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.setDescription.title"), SearchMessages.getString("Search.Error.setDescription.message")); //$NON-NLS-2$ //$NON-NLS-1$ - } - } - - - public void startup() throws CoreException { - super.startup(); - registerAdapters(); - } - - /** - * Shuts down this plug-in. - */ - public void shutdown() throws CoreException { - unregisterAdapters(); - getWorkspace().removeResourceChangeListener(SearchManager.getDefault()); - super.shutdown(); - fgSearchPlugin = null; - } - - /** - * Returns all search pages contributed to the workbench. - */ - public List getSearchPageDescriptors() { - if (fPageDescriptors == null) { - IPluginRegistry registry= Platform.getPluginRegistry(); - IConfigurationElement[] elements= registry.getConfigurationElementsFor(SearchUI.PLUGIN_ID, SEARCH_PAGE_EXTENSION_POINT); - fPageDescriptors= createSearchPageDescriptors(elements); - } - return fPageDescriptors; - } - - /** - * Returns all search pages contributed to the workbench. - */ - public List getEnabledSearchPageDescriptors(String pageId) { - Iterator iter= getSearchPageDescriptors().iterator(); - List enabledDescriptors= new ArrayList(5); - while (iter.hasNext()) { - SearchPageDescriptor desc= (SearchPageDescriptor)iter.next(); - if (desc.isEnabled() || desc.getId().equals(pageId)) - enabledDescriptors.add(desc); - } - return enabledDescriptors; - } - - /** - * Creates all necessary search page nodes. - */ - private List createSearchPageDescriptors(IConfigurationElement[] elements) { - List result= new ArrayList(5); - for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (SearchPageDescriptor.PAGE_TAG.equals(element.getName())) { - SearchPageDescriptor desc= new SearchPageDescriptor(element); - result.add(desc); - } - } - Collections.sort(result); - return result; - } - - /** - * Returns all sorters contributed to the workbench. - */ - public List getSorterDescriptors() { - if (fSorterDescriptors == null) { - IPluginRegistry registry= Platform.getPluginRegistry(); - IConfigurationElement[] elements= registry.getConfigurationElementsFor(SearchUI.PLUGIN_ID, SORTER_EXTENSION_POINT); - fSorterDescriptors= createSorterDescriptors(elements); - } - return fSorterDescriptors; - } - - /** - * Creates all necessary sorter description nodes. - */ - private List createSorterDescriptors(IConfigurationElement[] elements) { - List result= new ArrayList(5); - for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (SorterDescriptor.SORTER_TAG.equals(element.getName())) - result.add(new SorterDescriptor(element)); - } - return result; - } - - /** - * Log status to platform log - */ - public static void log(IStatus status) { - getDefault().getLog().log(status); - } - - /** - * Creates the Search plugin standard groups in a context menu. - */ - public static void createStandardGroups(IMenuManager menu) { - if (!menu.isEmpty()) - return; - menu.add(new Separator(IContextMenuConstants.GROUP_NEW)); - menu.add(new GroupMarker(IContextMenuConstants.GROUP_GOTO)); - menu.add(new GroupMarker(IContextMenuConstants.GROUP_OPEN)); - menu.add(new Separator(IContextMenuConstants.GROUP_SHOW)); - menu.add(new Separator(IContextMenuConstants.GROUP_BUILD)); - menu.add(new Separator(IContextMenuConstants.GROUP_REORGANIZE)); - menu.add(new Separator(IContextMenuConstants.GROUP_REMOVE_MATCHES)); - menu.add(new GroupMarker(IContextMenuConstants.GROUP_GENERATE)); - menu.add(new Separator(IContextMenuConstants.GROUP_SEARCH)); - menu.add(new Separator(IContextMenuConstants.GROUP_ADDITIONS)); - menu.add(new Separator(IContextMenuConstants.GROUP_VIEWER_SETUP)); - menu.add(new Separator(IContextMenuConstants.GROUP_PROPERTIES)); - } - - private void registerAdapters() { - IAdapterManager manager= Platform.getAdapterManager(); - fSearchResultViewEntryAdapterFactory= new SearchResultViewEntryAdapterFactory(); - manager.registerAdapters(fSearchResultViewEntryAdapterFactory, ISearchResultViewEntry.class); - } - - private void unregisterAdapters() { - IAdapterManager manager= Platform.getAdapterManager(); - manager.unregisterAdapters(fSearchResultViewEntryAdapterFactory); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java deleted file mode 100644 index 7d39d012783..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPluginImages.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -/** - * Bundle of all images used by the Search UI plugin. - */ -public class SearchPluginImages { - - private static URL fgIconLocation; - - static { - String pathSuffix= "icons/full/"; //$NON-NLS-1$ - try { - fgIconLocation= new URL(SearchPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix); - } catch (MalformedURLException ex) { - ExceptionHandler.log(ex, SearchMessages.getString("Search.Error.incorrectIconLocation.message")); //$NON-NLS-1$ - } - } - - // The plugin registry - private final static ImageRegistry PLUGIN_REGISTRY= SearchPlugin.getDefault().getImageRegistry(); - - public static final String T_OBJ= "obj16/"; //$NON-NLS-1$ - public static final String T_WIZBAN= "wizban/"; //$NON-NLS-1$ - public static final String T_LCL= "lcl16/"; //$NON-NLS-1$ - public static final String T_TOOL= "tool16/"; //$NON-NLS-1$ - public static final String T_VIEW= "view16/"; //$NON-NLS-1$ - - private static final String NAME_PREFIX= "org.eclipse.search.ui."; //$NON-NLS-1$ - private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length(); - - // Define image names - public static final String IMG_TOOL_SEARCH= NAME_PREFIX + "search.gif"; //$NON-NLS-1$ - - public static final String IMG_LCL_SEARCH_STOP= NAME_PREFIX + "search_stop.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_REM= NAME_PREFIX + "search_rem.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_REM_ALL= NAME_PREFIX + "search_remall.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_NEXT= NAME_PREFIX + "search_next.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_PREV= NAME_PREFIX + "search_prev.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_GOTO= NAME_PREFIX + "search_goto.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_SORT= NAME_PREFIX + "search_sortmatch.gif"; //$NON-NLS-1$ - public static final String IMG_LCL_SEARCH_HISTORY= NAME_PREFIX + "search_history.gif"; //$NON-NLS-1$ - - public static final String IMG_VIEW_SEARCHRES= NAME_PREFIX + "searchres.gif"; //$NON-NLS-1$ - - public static final String IMG_OBJ_TSEARCH= NAME_PREFIX + "tsearch_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TSEARCH_DPDN= NAME_PREFIX + "tsearch_dpdn_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_SEARCHMARKER= NAME_PREFIX + "searchm_obj.gif"; //$NON-NLS-1$ - - - - // Define images - public static final ImageDescriptor DESC_OBJ_TSEARCH= createManaged(T_OBJ, IMG_OBJ_TSEARCH); - public static final ImageDescriptor DESC_OBJ_TSEARCH_DPDN= createManaged(T_OBJ, IMG_OBJ_TSEARCH_DPDN); - public static final ImageDescriptor DESC_OBJ_SEARCHMARKER= createManaged(T_OBJ, IMG_OBJ_SEARCHMARKER); - - public static Image get(String key) { - return PLUGIN_REGISTRY.get(key); - } - - private static ImageDescriptor createManaged(String prefix, String name) { - ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH))); - PLUGIN_REGISTRY.put(name, result); - return result; - } - - private static ImageDescriptor create(String prefix, String name) { - return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); - } - - private static URL makeIconFileURL(String prefix, String name) { - StringBuffer buffer= new StringBuffer(prefix); - buffer.append(name); - try { - return new URL(fgIconLocation, buffer.toString()); - } catch (MalformedURLException ex) { - ExceptionHandler.log(ex, SearchMessages.getString("Search.Error.incorrectIconLocation.message")); //$NON-NLS-1$ - return null; - } - } - - /** - * Sets all available image descriptors for the given action. - */ - public static void setImageDescriptors(IAction action, String type, String relPath) { - relPath= relPath.substring(NAME_PREFIX_LENGTH); - action.setDisabledImageDescriptor(create("d" + type, relPath)); //$NON-NLS-1$ - action.setHoverImageDescriptor(create("c" + type, relPath)); //$NON-NLS-1$ - action.setImageDescriptor(create("e" + type, relPath)); //$NON-NLS-1$ - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java deleted file mode 100644 index 176376235d3..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; - -import org.eclipse.jface.preference.BooleanFieldEditor; -import org.eclipse.jface.preference.ColorFieldEditor; -import org.eclipse.jface.preference.FieldEditorPreferencePage; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.util.PropertyChangeEvent; - -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.help.WorkbenchHelp; - -/* - * The page for setting the Search preferences. - */ -public class SearchPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { - - public static final String IGNORE_POTENTIAL_MATCHES= "org.eclipse.search.potentialMatch.ignore"; //$NON-NLS-1$ - public static final String EMPHASIZE_POTENTIAL_MATCHES= "org.eclipse.search.potentialMatch.emphasize"; //$NON-NLS-1$ - public static final String POTENTIAL_MATCH_FG_COLOR= "org.eclipse.search.potentialMatch.fgColor"; //$NON-NLS-1$ - public static final String REUSE_EDITOR= "org.eclipse.search.reuseEditor"; //$NON-NLS-1$ - - private ColorFieldEditor fColorEditor; - private BooleanFieldEditor fEmphasizedCheckbox; - private BooleanFieldEditor fIgnorePotentialMatchesCheckbox; - private Composite fParent; - - public SearchPreferencePage() { - super(GRID); - setPreferenceStore(SearchPlugin.getDefault().getPreferenceStore()); - } - - public static void initDefaults(IPreferenceStore store) { - RGB gray= new RGB(85, 85, 85); - store.setDefault(EMPHASIZE_POTENTIAL_MATCHES, true); - store.setDefault(IGNORE_POTENTIAL_MATCHES, false); - PreferenceConverter.setDefault(store, POTENTIAL_MATCH_FG_COLOR, gray); - store.setDefault(REUSE_EDITOR, false); - } - - public static boolean isEditorReused() { - IPreferenceStore store= SearchPlugin.getDefault().getPreferenceStore(); - return store.getBoolean(REUSE_EDITOR); - } - - public static boolean arePotentialMatchesIgnored() { - IPreferenceStore store= SearchPlugin.getDefault().getPreferenceStore(); - return store.getBoolean(IGNORE_POTENTIAL_MATCHES); - } - - public static boolean arePotentialMatchesEmphasized() { - IPreferenceStore store= SearchPlugin.getDefault().getPreferenceStore(); - return store.getBoolean(EMPHASIZE_POTENTIAL_MATCHES); - } - - public static RGB getPotentialMatchBackgroundColor() { - IPreferenceStore store= SearchPlugin.getDefault().getPreferenceStore(); - return PreferenceConverter.getColor(store, POTENTIAL_MATCH_FG_COLOR); - } - - public void createControl(Composite parent) { - super.createControl(parent); - WorkbenchHelp.setHelp(getControl(), ISearchHelpContextIds.SEARCH_PREFERENCE_PAGE); - } - - protected void createFieldEditors() { - BooleanFieldEditor boolEditor= new BooleanFieldEditor( - REUSE_EDITOR, - SearchMessages.getString("SearchPreferencePage.reuseEditor"), //$NON-NLS-1$ - getFieldEditorParent() - ); - addField(boolEditor); - - fIgnorePotentialMatchesCheckbox= new BooleanFieldEditor( - IGNORE_POTENTIAL_MATCHES, - SearchMessages.getString("SearchPreferencePage.ignorePotentialMatches"), //$NON-NLS-1$ - getFieldEditorParent()); - addField(fIgnorePotentialMatchesCheckbox); - - fEmphasizedCheckbox= new BooleanFieldEditor( - EMPHASIZE_POTENTIAL_MATCHES, - SearchMessages.getString("SearchPreferencePage.emphasizePotentialMatches"), //$NON-NLS-1$ - getFieldEditorParent()); - addField(fEmphasizedCheckbox); - - fColorEditor= new ColorFieldEditor( - POTENTIAL_MATCH_FG_COLOR, - SearchMessages.getString("SearchPreferencePage.potentialMatchFgColor"), //$NON-NLS-1$ - getFieldEditorParent() - ); - addField(fColorEditor); - - fEmphasizedCheckbox.setEnabled(!arePotentialMatchesIgnored(), getFieldEditorParent()); - fColorEditor.setEnabled(!arePotentialMatchesIgnored() && arePotentialMatchesEmphasized(), getFieldEditorParent()); - } - - public void propertyChange(PropertyChangeEvent event) { - boolean arePotentialMatchesIgnored= fIgnorePotentialMatchesCheckbox.getBooleanValue(); - fEmphasizedCheckbox.setEnabled(!arePotentialMatchesIgnored, getFieldEditorParent()); - fColorEditor.setEnabled(!arePotentialMatchesIgnored && fEmphasizedCheckbox.getBooleanValue(), getFieldEditorParent()); - } - - public void init(IWorkbench workbench) { - } - - protected void performDefaults() { - super.performDefaults(); - boolean arePotentialMatchesIgnored= fIgnorePotentialMatchesCheckbox.getBooleanValue(); - fEmphasizedCheckbox.setEnabled(!arePotentialMatchesIgnored, getFieldEditorParent()); - fColorEditor.setEnabled(!arePotentialMatchesIgnored && fEmphasizedCheckbox.getBooleanValue(), getFieldEditorParent()); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultContentProvider.java deleted file mode 100644 index 88e9b661e9e..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultContentProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -class SearchResultContentProvider implements IStructuredContentProvider { - - private static final Object[] fgEmptyArray= new Object[0]; - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // Do nothing since the viewer listens to resource deltas - } - - public void dispose() { - } - - public boolean isDeleted(Object element) { - return false; - } - - public Object[] getElements(Object element) { - if (element instanceof ArrayList) - return ((ArrayList)element).toArray(); - else - return fgEmptyArray; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java deleted file mode 100644 index 61b42322b3d..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultLabelProvider.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.LabelProvider; - -import org.eclipse.ui.PlatformUI; - -import org.eclipse.search.ui.ISearchResultViewEntry; - -class SearchResultLabelProvider extends LabelProvider { - - private static final String MATCHES_POSTFIX= " " + SearchMessages.getString("SearchResultView.matches") + ")"; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - - private ILabelProvider fLabelProvider; - - - SearchResultLabelProvider(ILabelProvider provider) { - fLabelProvider= provider; - } - - public String getText(Object element) { - StringBuffer buf= new StringBuffer(getLabelProvider().getText(element)); - int count= ((ISearchResultViewEntry)element).getMatchCount(); - if (count > 1) { - buf.append(" ("); //$NON-NLS-1$ - buf.append(count); - buf.append(MATCHES_POSTFIX); - } - return buf.toString(); - } - - public Image getImage(Object element) { - return fLabelProvider.getImage(element); - } - - // Don't dispose since label providers are reused. - public void dispose() { - } - - ILabelProvider getLabelProvider() { - return fLabelProvider; - } - - public void addListener(ILabelProviderListener listener) { - super.addListener(listener); - fLabelProvider.addListener(listener); - PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator().addListener(listener); - } - - public boolean isLabelProperty(Object element, String property) { - return fLabelProvider.isLabelProperty(element, property); - } - - public void removeListener(ILabelProviderListener listener) { - super.removeListener(listener); - fLabelProvider.removeListener(listener); - PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator().removeListener(listener); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java deleted file mode 100644 index 5a2fe4d2d01..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; - -import org.eclipse.ui.IMemento; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.part.CellEditorActionHandler; -import org.eclipse.ui.part.ViewPart; - -import org.eclipse.search.ui.IActionGroupFactory; -import org.eclipse.search.ui.IContextMenuContributor; -import org.eclipse.search.ui.IGroupByKeyComputer; -import org.eclipse.search.ui.ISearchResultView; - - -public class SearchResultView extends ViewPart implements ISearchResultView { - - - private static Map fgLabelProviders= new HashMap(5);; - - private SearchResultViewer fViewer; - private Map fResponse; - private IMemento fMemento; - private IPropertyChangeListener fPropertyChangeListener; - private CellEditorActionHandler fCellEditorActionHandler; - private SelectAllAction fSelectAllAction; - - /* - * Implements method from IViewPart. - */ - public void init(IViewSite site, IMemento memento) throws PartInitException { - super.init(site, memento); - fMemento= memento; - } - - /* - * Implements method from IViewPart. - */ - public void saveState(IMemento memento) { - if (fViewer == null) { - // part has not been created - if (fMemento != null) //Keep the old state; - memento.putMemento(fMemento); - return; - } - fViewer.saveState(memento); - } - - /** - * Creates the search list inner viewer. - */ - public void createPartControl(Composite parent) { - Assert.isTrue(fViewer == null); - fViewer= new SearchResultViewer(this, parent); - if (fMemento != null) - fViewer.restoreState(fMemento); - fMemento= null; - SearchManager.getDefault().addSearchChangeListener(fViewer); - fViewer.init(); - fillToolBar(getViewSite().getActionBars().getToolBarManager()); - - // Add selectAll action handlers. - fCellEditorActionHandler = new CellEditorActionHandler(getViewSite().getActionBars()); - fSelectAllAction= new SelectAllAction(fViewer); - fCellEditorActionHandler.setSelectAllAction(fSelectAllAction); - - fPropertyChangeListener= new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (SearchPreferencePage.POTENTIAL_MATCH_FG_COLOR.equals(event.getProperty()) || SearchPreferencePage.EMPHASIZE_POTENTIAL_MATCHES.equals(event.getProperty())) - if (fViewer != null) - fViewer.updatedPotentialMatchBgColor(); - } - }; - - SearchPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener); - - WorkbenchHelp.setHelp(fViewer.getControl(), ISearchHelpContextIds.SEARCH_VIEW); - } - - /** - * Returns the search result viewer. - */ - public SearchResultViewer getViewer() { - return fViewer; - } - - //---- IWorkbenchPart ------------------------------------------------------ - - - public void setFocus() { - fViewer.getControl().setFocus(); - } - - public void dispose() { - if (fViewer != null) { - SearchManager.getDefault().removeSearchChangeListener(fViewer); - fViewer= null; - } - if (fPropertyChangeListener != null) - SearchPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener); - if (fCellEditorActionHandler != null) { - fCellEditorActionHandler.dispose(); - fCellEditorActionHandler= null; - } - super.dispose(); - } - - protected void setTitle(String title) { - super.setTitle(title); - } - - protected void setTitleToolTip(String text) { - super.setTitleToolTip(text); - } - - //---- Adding Action to Toolbar ------------------------------------------- - - private void fillToolBar(IToolBarManager tbm) { - fViewer.fillToolBar(tbm); - } - - ILabelProvider getLabelProvider(String pageId) { - if (pageId != null) - return (ILabelProvider)fgLabelProviders.get(pageId); - return null; - } - - public ILabelProvider getLabelProvider() { - if (fViewer == null) - return null; - IBaseLabelProvider labelProvider= fViewer.getLabelProvider(); - if (labelProvider == null) - return null; - - return ((SearchResultLabelProvider)labelProvider).getLabelProvider(); - } - - private void setContextMenuContributor(final IContextMenuContributor contributor) { - // Make sure we are doing it in the right thread. - getDisplay().syncExec(new Runnable() { - public void run() { - getViewer().setContextMenuTarget(contributor); - } - }); - } - - private void setGotoMarkerAction(final IAction gotoMarkerAction) { - // Make sure we are doing it in the right thread. - getDisplay().syncExec(new Runnable() { - public void run() { - getViewer().setGotoMarkerAction(gotoMarkerAction); - } - }); - } - - - Display getDisplay() { - return fViewer.getControl().getDisplay(); - } - - - //---- ISearchResultView -------------------------------------------------- - - - /* - * Implements method from ISearchResultView - */ - public ISelection getSelection() { - return fViewer.getSelection(); - } - - /* - * Implements method from ISearchResultView - */ - public void searchStarted( - IActionGroupFactory groupFactory, - String singularLabel, - String pluralLabelPattern, - ImageDescriptor imageDescriptor, - String pageId, - ILabelProvider labelProvider, - IAction gotoAction, - IGroupByKeyComputer groupByKeyComputer, - IRunnableWithProgress operation) { - - - Assert.isNotNull(pageId); - Assert.isNotNull(pluralLabelPattern); - Assert.isNotNull(gotoAction); - - fResponse= new HashMap(500); - setGotoMarkerAction(gotoAction); - - ILabelProvider oldLabelProvider= (ILabelProvider)fgLabelProviders.get(pageId); - if (oldLabelProvider != null) - oldLabelProvider.dispose(); - fgLabelProviders.put(pageId, labelProvider); - - SearchManager.getDefault().addNewSearch( - new Search( - pageId, - singularLabel, - pluralLabelPattern, - null, - imageDescriptor, - fViewer.getGotoMarkerAction(), - groupFactory, - groupByKeyComputer, - operation)); - }; - - /** - * Implements method from ISearchResultView - * @deprecated As of build > 20011107, replaced by the new version with additonal parameter - */ - public void searchStarted( - String pageId, - String label, - ImageDescriptor imageDescriptor, - IContextMenuContributor contributor, - ILabelProvider labelProvider, - IAction gotoAction, - IGroupByKeyComputer groupByKeyComputer, - IRunnableWithProgress operation) { - - searchStarted(pageId, null, label, imageDescriptor, contributor, labelProvider, gotoAction, groupByKeyComputer, operation); - }; - - /** - * Implements method from ISearchResultView - * @deprecated As of build > 20020514 - */ - public void searchStarted( - String pageId, - String singularLabel, - String pluralLabelPattern, - ImageDescriptor imageDescriptor, - IContextMenuContributor contributor, - ILabelProvider labelProvider, - IAction gotoAction, - IGroupByKeyComputer groupByKeyComputer, - IRunnableWithProgress operation) { - - - Assert.isNotNull(pageId); - Assert.isNotNull(pluralLabelPattern); - Assert.isNotNull(gotoAction); - - fResponse= new HashMap(500); - setGotoMarkerAction(gotoAction); - - ILabelProvider oldLabelProvider= (ILabelProvider)fgLabelProviders.get(pageId); - if (oldLabelProvider != null) - oldLabelProvider.dispose(); - fgLabelProviders.put(pageId, labelProvider); - - SearchManager.getDefault().addNewSearch( - new Search( - pageId, - singularLabel, - pluralLabelPattern, - null, - imageDescriptor, - fViewer.getGotoMarkerAction(), - contributor, - groupByKeyComputer, - operation)); - }; - - /* - * Implements method from ISearchResultView - */ - public void addMatch(String description, Object groupByKey, IResource resource, IMarker marker) { - SearchResultViewEntry entry= (SearchResultViewEntry)fResponse.get(groupByKey); - if (entry == null) { - entry= new SearchResultViewEntry(groupByKey, resource); - fResponse.put(groupByKey, entry); - } - entry.add(marker); - } - - - /* - * Implements method from ISearchResultView - */ - public void searchFinished() { - SearchManager.getDefault().setCurrentResults(new ArrayList(fResponse.values())); - fResponse= null; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java deleted file mode 100644 index ed648a49bc7..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.PlatformObject; - -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -/** - * Represents an entry in the search result view - */ -public class SearchResultViewEntry extends PlatformObject implements ISearchResultViewEntry { - - private Object fGroupByKey= null; - private IResource fResource= null; - private IMarker fMarker= null; - private ArrayList fMarkers= null; - private ArrayList fAttributes; - private int fSelectedMarkerIndex; - private long fModificationStamp= IResource.NULL_STAMP; - - public SearchResultViewEntry(Object groupByKey, IResource resource) { - fGroupByKey= groupByKey; - fResource= resource; - if (fResource != null) - fModificationStamp= fResource.getModificationStamp(); - } - - //---- Accessors ------------------------------------------------ - public Object getGroupByKey() { - return fGroupByKey; - } - - void setGroupByKey(Object groupByKey) { - fGroupByKey= groupByKey; - } - - public IResource getResource() { - return fResource; - } - - public int getMatchCount() { - if (fMarkers != null) - return fMarkers.size(); - if (fMarkers == null && fMarker != null) - return 1; - return 0; - } - - boolean isPotentialMatch() { - if (fMarker != null) - return fMarker.getAttribute(SearchUI.POTENTIAL_MATCH, false); - return false; - } - - List getAttributesPerMarker() { - if (fAttributes == null) - return new ArrayList(0); - return fAttributes; - } - - public long getModificationStamp() { - return fModificationStamp; - } - - void clearMarkerList() { - fMarker= null; - if (fMarkers != null) - fMarkers.clear(); - } - - void add(IMarker marker) { - if (fMarker == null) { - fMarker= marker; - if (fMarkers != null) - fMarkers.add(marker); - return; - } - if (fMarkers == null) { - fMarkers= new ArrayList(10); - addByStartpos(fMarkers, fMarker); - } - addByStartpos(fMarkers, marker); - } - - void setSelectedMarkerIndex(int index) { - fSelectedMarkerIndex= index; - } - - public IMarker getSelectedMarker() { - fSelectedMarkerIndex= Math.min(fSelectedMarkerIndex, getMatchCount() - 1); - if (fMarkers == null && fMarker == null) - return null; - if (fMarkers != null && fSelectedMarkerIndex >= 0) - return (IMarker)fMarkers.get(fSelectedMarkerIndex); - return fMarker; - } - - public List getMarkers() { - if (fMarkers == null && fMarker == null) - return new ArrayList(0); - else if (fMarkers == null && fMarker != null) { - List markers= new ArrayList(1); - markers.add(fMarker); - return markers; - } - return fMarkers; - } - - boolean contains(IMarker marker) { - if (fMarkers == null && fMarker == null) - return false; - if (fMarkers == null) - return fMarker.equals(marker); - else - return fMarkers.contains(marker); - } - - void remove(IMarker marker) { - if (marker == null) - return; - - if (fMarkers == null) { - if (fMarker != null && fMarker.equals(marker)) - fMarker= null; - } - else { - fMarkers.remove(marker); - if (fMarkers.size() == 1) { - fMarker= (IMarker)fMarkers.get(0); - fMarkers= null; - } - } - } - - void backupMarkers() { - if (fResource != null) - fModificationStamp= fResource.getModificationStamp(); - List markers= getMarkers(); - fAttributes= new ArrayList(markers.size()); - Iterator iter= markers.iterator(); - while (iter.hasNext()) { - IMarker marker= (IMarker)iter.next(); - Map attributes= null; - try { - attributes= marker.getAttributes(); - } catch (CoreException ex) { - // don't backup corrupt marker - continue; - } - fAttributes.add(attributes); - } - } - - private void addByStartpos(ArrayList markers, IMarker marker) { - int startPos= marker.getAttribute(IMarker.CHAR_START, -1); - int i= 0; - int markerCount= markers.size(); - while (i < markerCount && startPos >= ((IMarker)markers.get(i)).getAttribute(IMarker.CHAR_START, -1)) - i++; - markers.add(i, marker); - if (i == 0) - fMarker= marker; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java deleted file mode 100644 index 81e2ef7fedc..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ - -package org.eclipse.search.internal.ui; - - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdapterFactory; - -import org.eclipse.search.ui.ISearchResultViewEntry; - -/** - * Implements basic UI support for Java elements. - * Implements handle to persistent support for Java elements. - */ -public class SearchResultViewEntryAdapterFactory implements IAdapterFactory { - - private static Class[] PROPERTIES= new Class[] { - IResource.class, - }; - - - public Class[] getAdapterList() { - return PROPERTIES; - } - - public Object getAdapter(Object element, Class key) { - - ISearchResultViewEntry entry= (ISearchResultViewEntry)element; - - if (IResource.class.equals(key)) { - IResource resource= entry.getResource(); - /* - * This is a trick to filter out dummy markers that - * have been attached to a project because there is no - * corresponding resource in the workspace. - */ - int type= resource.getType(); - if (type != IResource.PROJECT && type != IResource.ROOT) - return resource; - } - return null; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java deleted file mode 100644 index 202a9b42629..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java +++ /dev/null @@ -1,674 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - - -import java.util.ArrayList; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Widget; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.IOpenListener; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProviderChangedEvent; -import org.eclipse.jface.viewers.OpenEvent; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; - -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.actions.ActionContext; -import org.eclipse.ui.actions.ActionGroup; - -import org.eclipse.search.ui.IActionGroupFactory; -import org.eclipse.search.ui.IContextMenuConstants; -import org.eclipse.search.ui.IContextMenuContributor; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.ui.util.FileLabelProvider; - - -/** - * A special viewer to present search results. The viewer implements an - * optimized adding and removing strategy. Furthermore it manages - * contributions for search result types. For example the viewer's context - * menu differs if the search result has been generated by a text or - * a java search. - */ -public class SearchResultViewer extends TableViewer { - - private SearchResultView fOuterPart; - private boolean fFirstTime= true; - private ShowNextResultAction fShowNextResultAction; - private ShowPreviousResultAction fShowPreviousResultAction; - private GotoMarkerAction fGotoMarkerActionProxy; - private SearchAgainAction fSearchAgainAction; - private RemoveResultAction fRemoveSelectedMatchesAction; - private SortDropDownAction fSortDropDownAction; - private SearchDropDownAction fSearchDropDownAction; - private CopyToClipboardAction fCopyToClipboardAction; - private int fMarkerToShow; - private boolean fHandleSelectionChangedEvents= true; - private ISelection fLastSelection; - private boolean fCurrentMatchRemoved= false; - private Color fPotentialMatchFgColor; - private ActionGroup fActionGroup; - private IContextMenuContributor fContextMenuContributor; - private IActionGroupFactory fActionGroupFactory; - private IAction fGotoMarkerAction; - - private ResourceToItemsMapper fResourceToItemsMapper; - - public SearchResultViewer(SearchResultView outerPart, Composite parent) { - super(new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION)); - - fResourceToItemsMapper= new ResourceToItemsMapper(this); - - fOuterPart= outerPart; - Assert.isNotNull(fOuterPart); - - if (SearchPreferencePage.arePotentialMatchesEmphasized()) - fPotentialMatchFgColor= new Color(SearchPlugin.getDefault().getActiveWorkbenchShell().getDisplay(), SearchPreferencePage.getPotentialMatchBackgroundColor()); - - setUseHashlookup(true); - setContentProvider(new SearchResultContentProvider()); - - ILabelProvider labelProvider= new SearchResultLabelProvider(new FileLabelProvider(FileLabelProvider.SHOW_LABEL)); - setLabelProvider(labelProvider); - - boolean hasSearch= SearchManager.getDefault().getCurrentSearch() != null; - - - fShowNextResultAction= new ShowNextResultAction(this); - fShowNextResultAction.setEnabled(false); - fShowPreviousResultAction= new ShowPreviousResultAction(this); - fShowPreviousResultAction.setEnabled(false); - fGotoMarkerActionProxy= new GotoMarkerAction(this); - fGotoMarkerActionProxy.setEnabled(false); - fRemoveSelectedMatchesAction= new RemoveResultAction(this, false); - fRemoveSelectedMatchesAction.setEnabled(false); - fSearchAgainAction= new SearchAgainAction(); - fSearchAgainAction.setEnabled(hasSearch); - fSortDropDownAction = new SortDropDownAction(this); - fSortDropDownAction.setEnabled(getItemCount() > 0); - fSearchDropDownAction= new SearchDropDownAction(this); - fSearchDropDownAction.setEnabled(hasSearch); - fCopyToClipboardAction= new CopyToClipboardAction(this); - - addSelectionChangedListener( - new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if (fLastSelection == null || !fLastSelection.equals(event.getSelection())) { - fLastSelection= event.getSelection(); - handleSelectionChanged(); - } - } - } - ); - - addOpenListener(new IOpenListener() { - public void open(OpenEvent event) { - showResult(); - } - }); - - MenuManager menuMgr= new MenuManager("#PopUp"); //$NON-NLS-1$ - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener( - new IMenuListener() { - public void menuAboutToShow(IMenuManager mgr) { - SearchPlugin.createStandardGroups(mgr); - fillContextMenu(mgr); - } - }); - Menu menu= menuMgr.createContextMenu(getTable()); - getTable().setMenu(menu); - - // Register menu - fOuterPart.getSite().registerContextMenu(menuMgr, this); - - IActionBars actionBars= fOuterPart.getViewSite().getActionBars(); - if (actionBars != null) { - actionBars.setGlobalActionHandler(IWorkbenchActionConstants.NEXT, fShowNextResultAction); - actionBars.setGlobalActionHandler(IWorkbenchActionConstants.PREVIOUS, fShowPreviousResultAction); - } - - fOuterPart.getSite().setSelectionProvider(this); - } - - void init() { - Search search= SearchManager.getDefault().getCurrentSearch(); - if (search != null) { - setGotoMarkerAction(search.getGotoMarkerAction()); - setContextMenuTarget(search.getContextMenuContributor()); - setActionGroupFactory(null); - setActionGroupFactory(search.getActionGroupFactory()); - setPageId(search.getPageId()); - setInput(search.getResults()); - } - } - - /** - * @see StructuredViewer#doUpdateItem(Widget, Object, boolean) - */ - protected void doUpdateItem(Widget item, Object element, boolean fullMap) { - super.doUpdateItem(item, element, fullMap); - if (((SearchResultViewEntry)element).isPotentialMatch()) { - TableItem ti = (TableItem) item; - ti.setForeground(fPotentialMatchFgColor); - } - } - - private void handleSelectionChanged() { - int selectionCount= getSelectedEntriesCount(); - boolean hasSingleSelection= selectionCount == 1; - boolean hasElements= getItemCount() > 0; - fShowNextResultAction.setEnabled(hasSingleSelection || (hasElements && selectionCount == 0)); - fShowPreviousResultAction.setEnabled(hasSingleSelection || (hasElements && selectionCount == 0)); - fGotoMarkerActionProxy.setEnabled(hasSingleSelection); - fRemoveSelectedMatchesAction.setEnabled(selectionCount > 0); - - if (fHandleSelectionChangedEvents) { - fMarkerToShow= -1; - fCurrentMatchRemoved= false; - } else - fHandleSelectionChangedEvents= true; - - updateStatusLine(); - } - - void updateStatusLine() { - boolean hasSingleSelection= getSelectedEntriesCount() == 1; - String location= ""; //$NON-NLS-1$ - if (hasSingleSelection) { - ISearchResultViewEntry entry= (ISearchResultViewEntry)getTable().getItem(getTable().getSelectionIndex()).getData(); - IPath path= entry.getResource().getFullPath(); - if (path != null) - location= path.makeRelative().toString(); - } - setStatusLineMessage(location); - } - - void enableActions() { - /* - * Note: The check before each set operation reduces flickering - */ - boolean state= getItemCount() > 0; - if (state != fShowNextResultAction.isEnabled()) - fShowNextResultAction.setEnabled(state); - if (state != fShowPreviousResultAction.isEnabled()) - fShowPreviousResultAction.setEnabled(state); - if (state != fSortDropDownAction.isEnabled()) - fSortDropDownAction.setEnabled(state); - - state= SearchManager.getDefault().getCurrentSearch() != null; - if (state != fSearchDropDownAction.isEnabled()) - fSearchDropDownAction.setEnabled(state); - if (state != fSearchAgainAction.isEnabled()) - fSearchAgainAction.setEnabled(state); - - state= !getSelection().isEmpty(); - if (state != fGotoMarkerActionProxy.isEnabled()) - fGotoMarkerActionProxy.setEnabled(state); - if (state != fRemoveSelectedMatchesAction.isEnabled()) - fRemoveSelectedMatchesAction.setEnabled(state); - } - - - protected void inputChanged(Object input, Object oldInput) { - fLastSelection= null; - getTable().removeAll(); - super.inputChanged(input, oldInput); - fMarkerToShow= -1; - fCurrentMatchRemoved= false; - updateTitle(); - enableActions(); - if (getItemCount() > 0) - selectResult(getTable(), 0); - } - - protected int getSelectedEntriesCount() { - ISelection s= getSelection(); - if (s == null || s.isEmpty() || !(s instanceof IStructuredSelection)) - return 0; - IStructuredSelection selection= (IStructuredSelection)s; - return selection.size(); - } - - //--- Contribution management ----------------------------------------------- - - - protected boolean enableRemoveMatchMenuItem() { - if (getSelectedEntriesCount() != 1) - return false; - Table table= getTable(); - int index= table.getSelectionIndex(); - SearchResultViewEntry entry= null; - if (index > -1) - entry= (SearchResultViewEntry)table.getItem(index).getData(); - return (entry != null && entry.getMatchCount() > 1); - - } - - void fillContextMenu(IMenuManager menu) { - ISelection selection= getSelection(); - - if (fActionGroup != null) { - ActionContext context= new ActionContext(selection); - context.setInput(getInput()); - fActionGroup.setContext(context); - fActionGroup.fillContextMenu(menu); - fActionGroup.setContext(null); - } - - if (fContextMenuContributor != null) - fContextMenuContributor.fill(menu, this); - - if (!selection.isEmpty()) { - menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, fCopyToClipboardAction); - menu.appendToGroup(IContextMenuConstants.GROUP_GOTO, fGotoMarkerActionProxy); - if (enableRemoveMatchMenuItem()) - menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemoveMatchAction(this)); - menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemoveResultAction(this, true)); - - if (isPotentialMatchSelected()) - menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemovePotentialMatchesAction(fOuterPart.getViewSite())); - } - - // If we have elements - if (getItemCount() > 0) - menu.appendToGroup(IContextMenuConstants.GROUP_REMOVE_MATCHES, new RemoveAllResultsAction()); - - menu.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, fSearchAgainAction); - if (!selection.isEmpty()) - menu.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, fSortDropDownAction); - } - - private boolean isPotentialMatchSelected() { - ISelection selection= getSelection(); - if (selection instanceof IStructuredSelection) { - Object entry= ((IStructuredSelection)selection).getFirstElement(); - if (entry instanceof ISearchResultViewEntry) { - IMarker marker= ((ISearchResultViewEntry)entry).getSelectedMarker(); - return marker != null && marker.getAttribute(SearchUI.POTENTIAL_MATCH, false); - } - } - return false; - } - - IAction getGotoMarkerAction() { - // null as return value is covered (no action will take place) - return fGotoMarkerAction; - } - - void setGotoMarkerAction(IAction gotoMarkerAction) { - fGotoMarkerAction= gotoMarkerAction; - } - - - void setContextMenuTarget(IContextMenuContributor contributor) { - fContextMenuContributor= contributor; - } - - void setActionGroupFactory(IActionGroupFactory groupFactory) { - IActionBars actionBars= fOuterPart.getViewSite().getActionBars(); - if (fActionGroup != null) { - fActionGroup.dispose(); - fActionGroup= null; - } - - if (groupFactory != null) { - fActionGroup= groupFactory.createActionGroup(fOuterPart); - if (actionBars != null) - fActionGroup.fillActionBars(actionBars); - } - if (actionBars != null) - actionBars.updateActionBars(); - } - - void setPageId(String pageId) { - ILabelProvider labelProvider= fOuterPart.getLabelProvider(pageId); - if (labelProvider != null) - internalSetLabelProvider(labelProvider); - fSortDropDownAction.setPageId(pageId); - } - - void fillToolBar(IToolBarManager tbm) { - tbm.add(fShowNextResultAction); - tbm.add(fShowPreviousResultAction); -// tbm.add(fGotoMarkerAction); see bug 15275 - tbm.add(fRemoveSelectedMatchesAction); - tbm.add(new Separator()); - tbm.add(new OpenSearchDialogAction()); - tbm.add(fSearchDropDownAction); - - // need to hook F5 to table - getTable().addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent e) { - if (e.keyCode == SWT.F5) { - fSearchAgainAction.run(); - return; // performance - } - if (e.character == SWT.DEL) { - new RemoveResultAction(SearchResultViewer.this, true).run(); - return; // performance - } - } - }); - } - - int getItemCount() { - return SearchManager.getDefault().getCurrentItemCount(); - } - - void internalSetLabelProvider(ILabelProvider provider) { - setLabelProvider(new SearchResultLabelProvider(provider)); - } - - /** - * Makes the first marker of the current result entry - * visible in an editor. If no result - * is visible, this method does nothing. - */ - public void showResult() { - Table table= getTable(); - if (!canDoShowResult(table)) - return; - - - int index= table.getSelectionIndex(); - if (index < 0) - return; - SearchResultViewEntry entry= (SearchResultViewEntry)getTable().getItem(index).getData(); - - - fMarkerToShow= 0; - fCurrentMatchRemoved= false; - entry.setSelectedMarkerIndex(0); - openCurrentSelection(); - } - - - /** - * Makes the next result (marker) visible in an editor. If no result - * is visible, this method makes the first result visible. - */ - public void showNextResult() { - Table table= getTable(); - if (!canDoShowResult(table)) - return; - - int index= table.getSelectionIndex(); - SearchResultViewEntry entry= null; - if (index > -1) - entry= (SearchResultViewEntry)table.getItem(index).getData(); - - if (fCurrentMatchRemoved) - fCurrentMatchRemoved= false; - else - fMarkerToShow++; - if (entry == null || fMarkerToShow >= entry.getMatchCount()) { - // move selection - if (index == -1) { - index= 0; - } else { - index++; - if (index >= table.getItemCount()) - index= 0; - } - fMarkerToShow= 0; - entry= (SearchResultViewEntry)getTable().getItem(index).getData(); - selectResult(table, index); - } - entry.setSelectedMarkerIndex(fMarkerToShow); - openCurrentSelection(); - updateStatusLine(); - } - - - /** - * Makes the previous result (marker) visible. If there isn't any - * visible result, this method makes the last result visible. - */ - public void showPreviousResult() { - fCurrentMatchRemoved= false; - Table table= getTable(); - if (!canDoShowResult(table)) - return; - - int index= table.getSelectionIndex(); - SearchResultViewEntry entry; - - - fMarkerToShow--; - if (fMarkerToShow >= 0) - entry= (SearchResultViewEntry)getTable().getItem(getTable().getSelectionIndex()).getData(); - else { - // move selection - int count= table.getItemCount(); - if (index == -1) { - index= count - 1; - } else { - index--; - if (index < 0) - index= count - 1; - } - entry= (SearchResultViewEntry)getTable().getItem(index).getData(); - fMarkerToShow= entry.getMatchCount() - 1; - selectResult(table, index); - } - entry.setSelectedMarkerIndex(fMarkerToShow); - openCurrentSelection(); - updateStatusLine(); - } - - private boolean canDoShowResult(Table table) { - if (table == null || getItemCount() == 0) - return false; - return true; - } - - private void selectResult(Table table, int index) { - fHandleSelectionChangedEvents= false; - Object element= getElementAt(index); - if (element != null) - setSelection(new StructuredSelection(getElementAt(index)), true); - else - setSelection(StructuredSelection.EMPTY); - } - - private void openCurrentSelection() { - IAction action= getGotoMarkerAction(); - if (action != null) - action.run(); - } - - /** - * Updates the background color for potential matches. - */ - void updatedPotentialMatchBgColor() { - if (fPotentialMatchFgColor != null) - fPotentialMatchFgColor.dispose(); - fPotentialMatchFgColor= null; - if (SearchPreferencePage.arePotentialMatchesEmphasized()) - fPotentialMatchFgColor= new Color(SearchPlugin.getDefault().getActiveWorkbenchShell().getDisplay(), SearchPreferencePage.getPotentialMatchBackgroundColor()); - refresh(); - } - - /** - * Update the title - */ - protected void updateTitle() { - boolean hasCurrentSearch= SearchManager.getDefault().getCurrentSearch() != null; - String title; - if (hasCurrentSearch) { - String description= SearchManager.getDefault().getCurrentSearch().getFullDescription(); - title= SearchMessages.getFormattedString("SearchResultView.titleWithDescription", description); //$NON-NLS-1$ - } else - title= SearchMessages.getString("SearchResultView.title"); //$NON-NLS-1$ - if (title == null || !title.equals(fOuterPart.getTitle())) - fOuterPart.setTitle(title); - } - - /** - * Clear the title - */ - protected void clearTitle() { - String title= SearchMessages.getString("SearchResultView.title"); //$NON-NLS-1$ - if (title == null || !title.equals(fOuterPart.getTitle())) - fOuterPart.setTitle(title); - } - - /** - * Sets the message text to be displayed on the status line. - * The image on the status line is cleared. - */ - private void setStatusLineMessage(String message) { - fOuterPart.getViewSite().getActionBars().getStatusLineManager().setMessage(message); - } - - - protected void handleDispose(DisposeEvent event) { - fLastSelection= null; - Menu menu= getTable().getMenu(); - if (menu != null) - menu.dispose(); - if (fPotentialMatchFgColor != null) - fPotentialMatchFgColor.dispose(); - if (fActionGroup != null) { - fActionGroup.dispose(); - fActionGroup= null; - } - super.handleDispose(event); - } - - //--- Change event handling ------------------------------------------------- - - /** - * Handle a single add. - */ - protected void handleAddMatch(ISearchResultViewEntry entry) { - insert(entry, -1); - } - - /** - * Handle a single remove. - */ - protected void handleRemoveMatch(ISearchResultViewEntry entry) { - Widget item= findItem(entry); - if (entry.getMatchCount() == 0) - remove(entry); - else - updateItem(item, entry); - updateStatusLine(); - } - - /** - * Handle remove all. - */ - protected void handleRemoveAll() { - setContextMenuTarget(null); - setActionGroupFactory(null); - setInput(null); - } - - /** - * Handle an update of an entry. - */ - protected void handleUpdateMatch(ISearchResultViewEntry entry, boolean matchRemoved) { - Widget item= findItem(entry); - updateItem(item, entry); - if (matchRemoved && getSelectionFromWidget().contains(entry)) - fCurrentMatchRemoved= true; - } - - //--- Persistency ------------------------------------------------- - - void restoreState(IMemento memento) { - fSortDropDownAction.restoreState(memento); - } - - void saveState(IMemento memento) { - fSortDropDownAction.saveState(memento); - } - - /* - * @see ContentViewer#handleLabelProviderChanged(LabelProviderChangedEvent) - */ - protected void handleLabelProviderChanged(LabelProviderChangedEvent event) { - Object[] changed= event.getElements(); - if (changed != null && !fResourceToItemsMapper.isEmpty()) { - ArrayList others= new ArrayList(changed.length); - for (int i= 0; i < changed.length; i++) { - Object curr= changed[i]; - if (curr instanceof IResource) { - fResourceToItemsMapper.resourceChanged((IResource) curr); - } else { - others.add(curr); - } - } - if (others.isEmpty()) { - return; - } - event= new LabelProviderChangedEvent((IBaseLabelProvider) event.getSource(), others.toArray()); - } - super.handleLabelProviderChanged(event); - } - - /* - * @see StructuredViewer#mapElement(Object, Widget) - */ - protected void mapElement(Object element, Widget item) { - super.mapElement(element, item); - if (item instanceof Item) { - fResourceToItemsMapper.addToMap(element, (Item)item); - } - } - - /* - * @see StructuredViewer#unmapElement(Object, Widget) - */ - protected void unmapElement(Object element, Widget item) { - if (item instanceof Item) { - fResourceToItemsMapper.removeFromMap(element, (Item)item); - } - super.unmapElement(element, item); - } - - /* - * @see StructuredViewer#unmapAllElements() - */ - protected void unmapAllElements() { - fResourceToItemsMapper.clearMap(); - super.unmapAllElements(); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java deleted file mode 100644 index 3c28c7fc58f..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -import org.eclipse.ui.help.WorkbenchHelp; - -/** - * This action selects all entries currently showing in view. - */ -class SelectAllAction extends Action { - - private SearchResultViewer fViewer; - - /** - * Creates the action. - */ - SelectAllAction(SearchResultViewer viewer) { - super("selectAll"); //$NON-NLS-1$ - setText(SearchMessages.getString("SelectAllAction.label")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("SelectAllAction.tooltip")); //$NON-NLS-1$ - WorkbenchHelp.setHelp(this, ISearchHelpContextIds.SELECT_ALL_ACTION); - fViewer= viewer; - } - - /** - * Selects all resources in the view. - */ - public void run() { - fViewer.getTable().selectAll(); - // force viewer selection change - fViewer.setSelection(fViewer.getSelection()); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowNextResultAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowNextResultAction.java deleted file mode 100644 index 04b0b29d1b5..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowNextResultAction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -class ShowNextResultAction extends Action { - - private SearchResultViewer fViewer; - - public ShowNextResultAction(SearchResultViewer viewer) { - super(SearchMessages.getString("SearchResultView.showNext.text")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_NEXT); - setToolTipText(SearchMessages.getString("SearchResultView.showNext.tooltip")); //$NON-NLS-1$ - fViewer= viewer; - } - - public void run() { - fViewer.showNextResult(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowPreviousResultAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowPreviousResultAction.java deleted file mode 100644 index b5b82ed85e6..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowPreviousResultAction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -class ShowPreviousResultAction extends Action { - - private SearchResultViewer fViewer; - - public ShowPreviousResultAction(SearchResultViewer viewer) { - super(SearchMessages.getString("SearchResultView.showPrev.text")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_PREV); - setToolTipText(SearchMessages.getString("SearchResultView.showPrev.tooltip")); //$NON-NLS-1$ - fViewer= viewer; - } - - public void run() { - fViewer.showPreviousResult(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchAction.java deleted file mode 100644 index e75010c7654..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchAction.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import org.eclipse.jface.action.Action; - -import org.eclipse.core.resources.IMarker; - -class ShowSearchAction extends Action { - private Search fSearch; - private IMarker[] fMarkerArrayTemplate= new IMarker[0]; - - /** - * Create a new instance of this class - */ - public ShowSearchAction(Search search) { - fSearch= search; - String desc= search.getShortDescription(); - setText(desc); - setToolTipText(desc); - setImageDescriptor(search.getImageDescriptor()); - } - /** - * Invoke the resource wizard selection wizard - * - * @param browser org.eclipse.jface.parts.Window - */ - public void run() { - if (fSearch != SearchManager.getDefault().getCurrentSearch()) - SearchManager.getDefault().setCurrentSearch(fSearch); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java deleted file mode 100644 index faac8731093..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.LabelProvider; - -import org.eclipse.search.internal.ui.util.ListDialog; - -/** - * Invoke the resource creation wizard selection Wizard. - * This action will retarget to the active view. - */ -class ShowSearchesAction extends Action { - - private static final LabelProvider fgLabelProvider= new LabelProvider() { - public String getText(Object element) { - if (!(element instanceof ShowSearchAction)) - return ""; //$NON-NLS-1$ - return ((ShowSearchAction)element).getText(); - } - public Image getImage(Object element) { - if (!(element instanceof ShowSearchAction)) - return null; - return ((ShowSearchAction)element).getImageDescriptor().createImage(); - } - }; - - /** - * Create a new instance of this class - */ - public ShowSearchesAction() { - super(SearchMessages.getString("ShowOtherSearchesAction.label")); //$NON-NLS-1$ - setToolTipText(SearchMessages.getString("ShowOtherSearchesAction.tooltip")); //$NON-NLS-1$ - } - /* - * Overrides method from Action - */ - public void run() { - run(false); - } - - public void run(boolean showAll) { - Iterator iter= SearchManager.getDefault().getPreviousSearches().iterator(); - int cutOffSize; - if (showAll) - cutOffSize= 0; - else - cutOffSize= SearchDropDownAction.RESULTS_IN_DROP_DOWN; - int size= SearchManager.getDefault().getPreviousSearches().size() - cutOffSize; - Search selectedSearch= SearchManager.getDefault().getCurrentSearch(); - Action selectedAction = null; - ArrayList input= new ArrayList(size); - int i= 0; - while (iter.hasNext()) { - Search search= (Search)iter.next(); - if (i++ < cutOffSize) - continue; - Action action= new ShowSearchAction(search); - input.add(action); - if (selectedSearch == search) - selectedAction= action; - } - - // Open a list dialog. - String title; - String message; - if (showAll) { - title= SearchMessages.getString("PreviousSearchesDialog.title"); //$NON-NLS-1$ - message= SearchMessages.getString("PreviousSearchesDialog.message"); //$NON-NLS-1$ - } - else { - title= SearchMessages.getString("OtherSearchesDialog.title"); //$NON-NLS-1$ - message= SearchMessages.getString("OtherSearchesDialog.message"); //$NON-NLS-1$ - } - ListDialog dlg= new ListDialog(SearchPlugin.getActiveWorkbenchShell(),input, title, message, new SearchResultContentProvider(), fgLabelProvider); - if (selectedAction != null) { - Object[] selected= new Object[1]; - selected[0]= selectedAction; - dlg.setInitialSelections(selected); - } - if (dlg.open() == dlg.OK) { - List result= Arrays.asList(dlg.getResult()); - if (result != null && result.size() == 1) { - ((ShowSearchAction)result.get(0)).run(); - } - } - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java deleted file mode 100644 index 6a33220542c..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IMenuCreator; -import org.eclipse.jface.viewers.ViewerSorter; - -import org.eclipse.ui.IMemento; - -/** - * Drop down action that holds the currently registered sort actions. - */ -class SortDropDownAction extends Action implements IMenuCreator { - - // Persistance tags. - private static final String TAG_SORTERS= "sorters"; //$NON-NLS-1$ - private static final String TAG_DEFAULT_SORTERS= "defaultSorters"; //$NON-NLS-1$ - private static final String TAG_ELEMENT= "element"; //$NON-NLS-1$ - private static final String TAG_PAGE_ID= "pageId"; //$NON-NLS-1$ - private static final String TAG_SORTER_ID= "sorterId"; //$NON-NLS-1$ - - private static Map fgLastCheckedForType= new HashMap(5);; - - private SearchResultViewer fViewer; - private String fPageId; - private Menu fMenu; - private String fCheckedId; - private Map fLastCheckedForType; - - public SortDropDownAction(SearchResultViewer viewer) { - super(SearchMessages.getString("SortDropDownAction.label")); //$NON-NLS-1$ - SearchPluginImages.setImageDescriptors(this, SearchPluginImages.T_LCL, SearchPluginImages.IMG_LCL_SEARCH_SORT); - fViewer= viewer; - setToolTipText(SearchMessages.getString("SortDropDownAction.tooltip")); //$NON-NLS-1$ - setMenuCreator(this); - fLastCheckedForType= new HashMap(5); - } - - public void dispose() { - fViewer= null; - fPageId= null; - fLastCheckedForType= null; - } - - public Menu getMenu(Control parent) { - return null; - } - - void setPageId(String pageId) { - fPageId= pageId; - SorterDescriptor sorterDesc= (SorterDescriptor)fLastCheckedForType.get(pageId); - if (sorterDesc == null) - sorterDesc= (SorterDescriptor)fgLastCheckedForType.get(pageId); - if (sorterDesc == null) - sorterDesc= findSorter(fPageId); - if (sorterDesc != null) { - setChecked(sorterDesc); - fViewer.setSorter(sorterDesc.createObject()); - } - } - - public Menu getMenu(final Menu parent) { - boolean hasEntries= false; - Menu menu= new Menu(parent); - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); - while (iter.hasNext()) { - Object value= fLastCheckedForType.get(fPageId); - final String checkedId; - if (value instanceof SorterDescriptor) - checkedId= ((SorterDescriptor)value).getId(); - else - checkedId= ""; //$NON-NLS-1$ - - final SorterDescriptor sorterDesc= (SorterDescriptor) iter.next(); - if (!sorterDesc.getPageId().equals(fPageId) && !sorterDesc.getPageId().equals("*")) //$NON-NLS-1$ - continue; - final ViewerSorter sorter= sorterDesc.createObject(); - if (sorter != null) { - final Action action= new Action() { - public void run() { - if (!checkedId.equals(sorterDesc.getId())) { - SortDropDownAction.this.setChecked(sorterDesc); - BusyIndicator.showWhile(parent.getDisplay(), new Runnable() { - public void run() { - fViewer.setSorter(sorter); - } - }); - } - } - }; - action.setText(sorterDesc.getLabel()); - action.setImageDescriptor(sorterDesc.getImage()); - action.setToolTipText(sorterDesc.getToolTipText()); - action.setChecked(checkedId.equals(sorterDesc.getId())); - addActionToMenu(menu, action); - hasEntries= true; - } - } - setEnabled(hasEntries); - return menu; - } - - protected void addActionToMenu(Menu parent, Action action) { - ActionContributionItem item= new ActionContributionItem(action); - item.fill(parent, -1); - } - - public void run() { - // nothing to do - } - - private SorterDescriptor findSorter(String pageId) { - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); - while (iter.hasNext()) { - SorterDescriptor sorterDesc= (SorterDescriptor)iter.next(); - if (sorterDesc.getPageId().equals(pageId) || sorterDesc.getPageId().equals("*")) //$NON-NLS-1$ - return sorterDesc; - } - return null; - } - - private SorterDescriptor getSorter(String sorterId) { - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); - while (iter.hasNext()) { - SorterDescriptor sorterDesc= (SorterDescriptor)iter.next(); - if (sorterDesc.getId().equals(sorterId)) - return sorterDesc; - } - return null; - } - - private void setChecked(SorterDescriptor sorterDesc) { - fLastCheckedForType.put(fPageId, sorterDesc); - fgLastCheckedForType.put(fPageId, sorterDesc); - } - - //--- Persistency ------------------------------------------------- - - void restoreState(IMemento memento) { - if (fLastCheckedForType.isEmpty()) - restoreState(memento, fLastCheckedForType, TAG_SORTERS); - if (fgLastCheckedForType.isEmpty()) - restoreState(memento, fgLastCheckedForType, TAG_DEFAULT_SORTERS); - } - - private void restoreState(IMemento memento, Map map, String mapName) { - memento= memento.getChild(mapName); - if (memento == null) - return; - IMemento[] mementoElements= memento.getChildren(TAG_ELEMENT); - for (int i= 0; i < mementoElements.length; i++) { - String pageId= mementoElements[i].getString(TAG_PAGE_ID); - String sorterId= mementoElements[i].getString(TAG_SORTER_ID); - SorterDescriptor sorterDesc= getSorter(sorterId); - if (sorterDesc != null) - map.put(pageId, sorterDesc); - } - } - - void saveState(IMemento memento) { - saveState(memento, fgLastCheckedForType, TAG_DEFAULT_SORTERS); - saveState(memento, fLastCheckedForType, TAG_SORTERS); - } - - private void saveState(IMemento memento, Map map, String mapName) { - Iterator iter= map.entrySet().iterator(); - memento= memento.createChild(mapName); - while (iter.hasNext()) { - IMemento mementoElement= memento.createChild(TAG_ELEMENT); - Map.Entry entry= (Map.Entry)iter.next(); - mementoElement.putString(TAG_PAGE_ID, (String)entry.getKey()); - mementoElement.putString(TAG_SORTER_ID, ((SorterDescriptor)entry.getValue()).getId()); - } - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SorterDescriptor.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SorterDescriptor.java deleted file mode 100644 index 3b2338ff34b..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SorterDescriptor.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.net.URL; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ViewerSorter; - -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -/** - * Proxy that represents a sorter. - */ -class SorterDescriptor { - - public final static String SORTER_TAG= "sorter"; //$NON-NLS-1$ - private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ - private final static String PAGE_ID_ATTRIBUTE= "pageId"; //$NON-NLS-1$ - private final static String ICON_ATTRIBUTE= "icon"; //$NON-NLS-1$ - private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$ - private final static String LABEL_ATTRIBUTE= "label"; //$NON-NLS-1$ - private final static String TOOLTIP_ATTRIBUTE= "tooltip"; //$NON-NLS-1$ - - private IConfigurationElement fElement; - - /** - * Creates a new sorter node with the given configuration element. - */ - public SorterDescriptor(IConfigurationElement element) { - fElement= element; - } - - /** - * Creates a new sorter from this node. - */ - public ViewerSorter createObject() { - try { - return (ViewerSorter)fElement.createExecutableExtension(CLASS_ATTRIBUTE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return null; - } catch (ClassCastException ex) { - ExceptionHandler.displayMessageDialog(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return null; - } - } - - //---- XML Attribute accessors --------------------------------------------- - - /** - * Returns the sorter's id. - */ - public String getId() { - return fElement.getAttribute(ID_ATTRIBUTE); - } - - /** - * Returns the sorter's image - */ - public ImageDescriptor getImage() { - String imageName= fElement.getAttribute(ICON_ATTRIBUTE); - if (imageName == null) - return null; - URL url; - try { - url= new URL(fElement.getDeclaringExtension().getDeclaringPluginDescriptor().getInstallURL(), imageName); - } catch (java.net.MalformedURLException ex) { - ExceptionHandler.log(ex, SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-1$ - return null; - } - return ImageDescriptor.createFromURL(url); - } - - /** - * Returns the sorter's label. - */ - public String getLabel() { - return fElement.getAttribute(LABEL_ATTRIBUTE); - } - - /** - * Returns the sorter's preferred size - */ - public String getToolTipText() { - return fElement.getAttribute(TOOLTIP_ATTRIBUTE); - } - - /** - * Returns the sorter's preferred size - */ - public String getPageId() { - return fElement.getAttribute(PAGE_ID_ATTRIBUTE); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java deleted file mode 100644 index 4a708997422..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui; - -import java.text.Collator; -import java.util.Comparator; - -import org.eclipse.ui.IWorkingSet; - -class WorkingSetComparator implements Comparator { - - private Collator fCollator= Collator.getInstance(); - - /* - * @see Comparator#compare(Object, Object) - */ - public int compare(Object o1, Object o2) { - String name1= null; - String name2= null; - - if (o1 instanceof IWorkingSet) - name1= ((IWorkingSet)o1).getName(); - - if (o2 instanceof IWorkingSet) - name2= ((IWorkingSet)o2).getName(); - - return fCollator.compare(name1, name2); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/GotoMarkerAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/GotoMarkerAction.java deleted file mode 100644 index d85f3e6469a..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/GotoMarkerAction.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; - -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.part.FileEditorInput; - -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -class GotoMarkerAction extends Action { - - private IEditorPart fEditor; - - public void run() { - ISearchResultView view= SearchUI.getSearchResultView(); - ISelection selection= view.getSelection(); - Object element= null; - if (selection instanceof IStructuredSelection) - element= ((IStructuredSelection)selection).getFirstElement(); - if (element instanceof ISearchResultViewEntry) { - ISearchResultViewEntry entry= (ISearchResultViewEntry)element; - show(entry.getSelectedMarker()); - } - } - - private void show(IMarker marker) { - if (SearchUI.reuseEditor()) - showWithReuse(marker); - else - showWithoutReuse(marker); - } - - private void showWithReuse(IMarker marker) { - IWorkbenchPage page= SearchPlugin.getActivePage(); - IResource resource= marker.getResource(); - if (page == null || !(resource instanceof IFile)) - return; - - IEditorInput input= new FileEditorInput((IFile)resource); - String editorId= null; - IEditorDescriptor desc= SearchPlugin.getDefault().getWorkbench().getEditorRegistry().getDefaultEditor((IFile)resource); - if (desc == null) - editorId= SearchPlugin.getDefault().getWorkbench().getEditorRegistry().getDefaultEditor().getId(); - else - editorId= desc.getId(); - - IEditorPart editor= page.findEditor(input); - if (editor == null) { - if (fEditor != null && !fEditor.isDirty()) - page.closeEditor(fEditor, false); - try { - editor= page.openEditor(input, editorId, false); - } catch (PartInitException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.openEditor.title"), SearchMessages.getString("Search.Error.openEditor.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return; - } - - } else { - page.bringToTop(editor); - } - if (editor != null) { - editor.gotoMarker(marker); - fEditor= editor; - } - } - - private void showWithoutReuse(IMarker marker) { - IWorkbenchPage page= SearchPlugin.getActivePage(); - if (page == null) - return; - - try { - page.openEditor(marker, false); - } catch (PartInitException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.openEditor.title"), SearchMessages.getString("Search.Error.openEditor.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return; - } - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/GroupByKeyComputer.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/GroupByKeyComputer.java deleted file mode 100644 index 1461072bd3e..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/GroupByKeyComputer.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import org.eclipse.core.resources.IMarker; - -import org.eclipse.search.ui.IGroupByKeyComputer; - -class GroupByKeyComputer implements IGroupByKeyComputer { - - public Object computeGroupByKey(IMarker marker) { - if (marker == null) - return null; - else - return marker.getResource(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java deleted file mode 100644 index 022fa74f2ae..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.search.internal.ui.text; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.Viewer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; - -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchSite; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.texteditor.ITextEditor; - -import org.eclipse.search.internal.ui.Search; -import org.eclipse.search.internal.ui.SearchManager; -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchResultViewEntry; -import org.eclipse.search.internal.ui.util.ListDialog; - -/* package */ class ReplaceAction extends Action { - - private IWorkbenchSite fSite; - private List fElements; - - public ReplaceAction(IWorkbenchSite site, List elements) { - Assert.isNotNull(site); - fSite= site; - if (elements != null) - fElements= elements; - else - fElements= new ArrayList(0); - setText(SearchMessages.getString("ReplaceAction.label_all")); //$NON-NLS-1$ - setEnabled(!fElements.isEmpty()); - } - - public ReplaceAction(IWorkbenchSite site, IStructuredSelection selection) { - Assert.isNotNull(site); - fSite= site; - setText(SearchMessages.getString("ReplaceAction.label_selected")); //$NON-NLS-1$ - fElements= selection.toList(); - setEnabled(!fElements.isEmpty()); - } - - public void run() { - if (validateResources()) { - Search search= SearchManager.getDefault().getCurrentSearch(); - IRunnableWithProgress operation= search.getOperation(); - if (operation instanceof TextSearchOperation) { - ReplaceDialog dialog= new ReplaceDialog(fSite.getShell(), fElements, fSite.getWorkbenchWindow(), ((TextSearchOperation)operation).getPattern()); - dialog.open(); - } else { - MessageDialog.openError(fSite.getShell(), getDialogTitle(), SearchMessages.getString("ReplaceAction.error.only_on_text_search")); //$NON-NLS-1$ - } - } - } - - private boolean validateResources() { - List modifiedFiles= new ArrayList(); - List openedFilesInNonTextEditor= new ArrayList(); - List notFiles= new ArrayList(); - IWorkbenchPage activePage = fSite.getWorkbenchWindow().getActivePage(); - - for (Iterator iter = fElements.iterator(); iter.hasNext();) { - SearchResultViewEntry entry= (SearchResultViewEntry) iter.next(); - IResource resource= entry.getResource(); - if (resource instanceof IFile) { - IFile file= (IFile)resource; - if (file.getModificationStamp() != entry.getModificationStamp() || !file.isSynchronized(IResource.DEPTH_ZERO)) { - modifiedFiles.add(resource); - } else if (activePage != null) { - IEditorPart part= activePage.findEditor(new FileEditorInput(file)); - if (part != null && !(part instanceof ITextEditor)) - openedFilesInNonTextEditor.add(file); - } - } else { - if (resource != null) - notFiles.add(resource); - } - } - if (!modifiedFiles.isEmpty()) { - showModifiedFileDialog(modifiedFiles); - return false; - } - if (!openedFilesInNonTextEditor.isEmpty()) { - showOpenedFileDialog(openedFilesInNonTextEditor); - return false; - } - if (!notFiles.isEmpty()) { - showNotFilesDialog(openedFilesInNonTextEditor); - return false; - } - IFile[] readOnlyFiles= getReadOnlyFiles(); - if (readOnlyFiles.length == 0) - return true; - Map currentStamps= createModificationStampMap(readOnlyFiles); - IStatus status= ResourcesPlugin.getWorkspace().validateEdit(readOnlyFiles, fSite.getShell()); - if (!status.isOK()) { - ErrorDialog.openError(fSite.getShell(), getDialogTitle(), SearchMessages.getString("ReplaceAction.error.unable_to_perform"), status); //$NON-NLS-1$ - return false; - } - modifiedFiles= new ArrayList(); - Map newStamps= createModificationStampMap(readOnlyFiles); - for (Iterator iter= currentStamps.keySet().iterator(); iter.hasNext();) { - IFile file= (IFile) iter.next(); - if (! currentStamps.get(file).equals(newStamps.get(file))) { - modifiedFiles.add(file); - } - } - if (!modifiedFiles.isEmpty()) { - showModifiedFileDialog(modifiedFiles); - return false; - } - return true; - } - - private void showModifiedFileDialog(List modifiedFiles) { - String message= (modifiedFiles.size() == 1 - ? SearchMessages.getString("ReplaceAction.error.changed_file") //$NON-NLS-1$ - : SearchMessages.getString("ReplaceAction.error.changed_files")); //$NON-NLS-1$ - ListDialog dialog= new ListDialog(fSite.getShell(), modifiedFiles, getDialogTitle(), - message, - new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - return ((List)inputElement).toArray(); - } - public void dispose() { - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }, - new WorkbenchLabelProvider()); - dialog.setCreateCancelButton(false); - dialog.open(); - } - - private IFile[] getReadOnlyFiles() { - List result= new ArrayList(); - for (Iterator iter = fElements.iterator(); iter.hasNext();) { - IResource resource= ((SearchResultViewEntry) iter.next()).getResource(); - if (resource instanceof IFile && resource.isReadOnly()) - result.add(resource); - } - return (IFile[]) result.toArray(new IFile[result.size()]); - } - - private static Map createModificationStampMap(IFile[] files){ - Map map= new HashMap(); - for (int i= 0; i < files.length; i++) { - IFile file= files[i]; - map.put(file, new Long(file.getModificationStamp())); - } - return map; - } - - private String getDialogTitle() { - return SearchMessages.getString("ReplaceAction.dialog.title"); //$NON-NLS-1$ - } - - private void showOpenedFileDialog(List openedFilesInNonTextEditor) { - String message= (openedFilesInNonTextEditor.size() == 1 - ? SearchMessages.getString("ReplaceAction.error.opened_file") //$NON-NLS-1$ - : SearchMessages.getString("ReplaceAction.error.opened_files")); //$NON-NLS-1$ - ListDialog dialog= new ListDialog(fSite.getShell(), openedFilesInNonTextEditor, getDialogTitle(), - message, - new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - return ((List)inputElement).toArray(); - } - public void dispose() { - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }, - new WorkbenchLabelProvider()); - dialog.setCreateCancelButton(false); - dialog.open(); - } - - private void showNotFilesDialog(List notFiles) { - String message= (notFiles.size() == 1 - ? SearchMessages.getString("ReplaceAction.error.not_file") //$NON-NLS-1$ - : SearchMessages.getString("ReplaceAction.error.not_files")); //$NON-NLS-1$ - ListDialog dialog= new ListDialog(fSite.getShell(), notFiles, getDialogTitle(), - message, - new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - return ((List)inputElement).toArray(); - } - public void dispose() { - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }, - new WorkbenchLabelProvider()); - dialog.setCreateCancelButton(false); - dialog.open(); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java deleted file mode 100644 index 4fd603c7a26..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java +++ /dev/null @@ -1,382 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.search.internal.ui.text; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.util.Assert; - -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.actions.GlobalBuildAction; -import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; -import org.eclipse.ui.texteditor.IDocumentProvider; -import org.eclipse.ui.texteditor.ITextEditor; - -import org.eclipse.search.ui.ISearchResultView; - -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.internal.ui.SearchResultView; -import org.eclipse.search.internal.ui.SearchResultViewEntry; -import org.eclipse.search.internal.ui.util.ExceptionHandler; - -public class ReplaceDialog extends Dialog { - - private static final int REPLACE_NEXT= IDialogConstants.CLIENT_ID; - private static final int REPLACE= IDialogConstants.CLIENT_ID + 1; - private static final int NEXT= IDialogConstants.CLIENT_ID + 2; - - private String fSearchPattern; - - private IWorkbenchWindow fWindow; - private boolean fAutobuild; - private boolean fFatalError; - - // UI - private Text fTextField; - private Button fSaveButton; - private Button fReplaceNextButton; - private Button fReplaceButton; - private Button fNextButton; - - - private boolean fSaved; - private ITextEditor fEditor; - private boolean fCloseEditor; - private IDocument fDocument; - private AbstractMarkerAnnotationModel fAnnotationModel; - - - private List fElements; - private int fElementIndex; - private SearchResultViewEntry fCurrentEntry; - private List fCurrentMarkers; - private int fMarkerIndex; - private IMarker fCurrentMatch; - - private static class MarkerNotPresentableException extends Exception { - private IFile fFile; - MarkerNotPresentableException(IFile file) { - fFile= file; - } - public IFile getFile() { - return fFile; - } - } - - protected ReplaceDialog(Shell parentShell, List elements, IWorkbenchWindow window, String searchPattern) { - super(parentShell); - Assert.isNotNull(elements); - Assert.isNotNull(searchPattern); - fElements= new ArrayList(elements); - Assert.isNotNull(window); - fWindow= window; - fSearchPattern= searchPattern; - } - - public void create() { - super.create(); - Shell shell= getShell(); - shell.setText(getDialogTitle()); - updateButtons(); - } - - public int open() { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - fAutobuild= workspace.isAutoBuilding(); - if (fAutobuild) { - IWorkspaceDescription description= workspace.getDescription(); - description.setAutoBuilding(false); - try { - workspace.setDescription(description); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.auto_building")); //$NON-NLS-1$ - fFatalError= true; - } - } - try { - fCurrentMatch= getNextMatch(false); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.no_matches")); //$NON-NLS-1$ - fFatalError= true; - } catch (MarkerNotPresentableException e) { - handleMarkerNotPresentableException(e); - fFatalError= true; - } - return super.open(); - } - - public boolean close() { - boolean result= super.close(); - restoreAutoBuildState(); - return result; - } - - protected Control createDialogArea(Composite parent) { - Composite result= (Composite)super.createDialogArea(parent); - GridLayout layout= (GridLayout)result.getLayout(); - layout.numColumns= 2; - - initializeDialogUnits(result); - - Label label= new Label(result, SWT.NONE); - label.setText(SearchMessages.getString("ReplaceDialog.replace_label")); //$NON-NLS-1$ - - CLabel clabel= new CLabel(result, SWT.NONE); - clabel.setText(fSearchPattern); - GridData gd= new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint= convertWidthInCharsToPixels(50); - clabel.setLayoutData(gd); - - label= new Label(result, SWT.NONE); - label.setText(SearchMessages.getString("ReplaceDialog.with_label")); //$NON-NLS-1$ - - fTextField= new Text(result, SWT.BORDER); - gd= new GridData(GridData.FILL_HORIZONTAL); - gd.widthHint= convertWidthInCharsToPixels(50); - fTextField.setLayoutData(gd); - fTextField.setFocus(); - - fSaveButton= new Button(result, SWT.CHECK); - fSaveButton.setText(SearchMessages.getString("ReplaceDialog.save_changes")); //$NON-NLS-1$ - fSaveButton.setSelection(true); - gd= new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan= 2; - fSaveButton.setLayoutData(gd); - - return result; - } - - protected void createButtonsForButtonBar(Composite parent) { - fReplaceNextButton= createButton(parent, REPLACE_NEXT, SearchMessages.getString("ReplaceDialog.replace_next"), false); //$NON-NLS-1$ - fReplaceButton= createButton(parent, REPLACE, SearchMessages.getString("ReplaceDialog.replace"), false); //$NON-NLS-1$ - fNextButton= createButton(parent, NEXT, SearchMessages.getString("ReplaceDialog.next"), false); //$NON-NLS-1$ - createButton(parent, IDialogConstants.CANCEL_ID, SearchMessages.getString("ReplaceDialog.close"), false); //$NON-NLS-1$ - } - - protected Point getInitialLocation(Point initialSize) { - SearchResultView view= (SearchResultView)SearchPlugin.getSearchResultView(); - if (view == null) - return super.getInitialLocation(initialSize); - Point result= new Point(0,0); - Control control= view.getViewer().getControl(); - Point size= control.getSize(); - Point location= control.toDisplay(control.getLocation()); - result.x= Math.max(0, location.x + size.x - initialSize.x); - result.y= Math.max(0, location.y + size. y - initialSize.y); - return result; - } - - protected void buttonPressed(int buttonId) { - try { - boolean save= fSaveButton.getSelection(); - String text= fTextField.getText(); - switch(buttonId) { - case REPLACE_NEXT: - replace(fCurrentMatch, text, save); - fCurrentMatch= getNextMatch(save); - break; - case REPLACE: - replace(fCurrentMatch, text, save); - fCurrentMatch= null; - break; - case NEXT: - fCurrentMatch= getNextMatch(save); - break; - case IDialogConstants.CANCEL_ID: - saveEditor(save); - break; - } - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.unexpected_exception")); //$NON-NLS-1$ - fFatalError= true; - } catch (BadLocationException e) { - MessageDialog.openError(getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.different_content")); //$NON-NLS-1$ - fFatalError= true; - } catch (MarkerNotPresentableException e) { - handleMarkerNotPresentableException(e); - fFatalError= true; - } - updateButtons(); - super.buttonPressed(buttonId); - } - - private void replace(IMarker source, String text, boolean save) throws CoreException, BadLocationException { - Position position= fAnnotationModel.getMarkerPosition(source); - fDocument.replace(position.getOffset(), position.getLength(), text); - SearchPlugin.getWorkspace().deleteMarkers(new IMarker[] {source}); - } - - private boolean isLastMatch() { - return fCurrentMatch != null && fCurrentMarkers == null; - } - - private boolean hasNextMatch() { - if (fCurrentMarkers != null) - return true; - return fElementIndex < fElements.size(); - } - - private IMarker getNextMatch(boolean save) throws CoreException, MarkerNotPresentableException { - if (fCurrentMarkers == null) { - if (fElementIndex >= fElements.size()) - return null; - saveEditor(save); - fCurrentEntry= (SearchResultViewEntry)fElements.get(fElementIndex++); - fCurrentMarkers= new ArrayList(fCurrentEntry.getMarkers()); - fMarkerIndex= 0; - } - IMarker result= (IMarker)fCurrentMarkers.get(fMarkerIndex); - if (fEditor == null) { - IWorkbenchPage activePage = fWindow.getActivePage(); - int openEditors= activePage.getEditorReferences().length; - - fEditor= openFile(result, activePage); - fEditor.gotoMarker(result); - IDocumentProvider provider= fEditor.getDocumentProvider(); - IEditorInput input = fEditor.getEditorInput(); - fDocument= provider.getDocument(input); - fAnnotationModel= (AbstractMarkerAnnotationModel)provider.getAnnotationModel(input); - fCloseEditor= openEditors < activePage.getEditorReferences().length; - } else { - fEditor.gotoMarker(result); - } - if (fMarkerIndex == fCurrentMarkers.size() - 1) { - fCurrentMarkers= null; - } else { - fMarkerIndex++; - } - return result; - } - - private ITextEditor openFile(IMarker marker, IWorkbenchPage activePage) throws MarkerNotPresentableException, PartInitException { - IFile markerFile= marker.getResource() instanceof IFile ? (IFile)marker.getResource() : null; - if (markerFile == null) - throw new MarkerNotPresentableException(null); - - String currentEditorId= null; - IEditorRegistry editorRegistry= SearchPlugin.getDefault().getWorkbench().getEditorRegistry(); - IEditorDescriptor desc= editorRegistry.getDefaultEditor(markerFile); - if (desc != null) - currentEditorId= desc.getId(); - try { - IEditorPart result= activePage.openEditor(markerFile, "org.eclipse.ui.DefaultTextEditor", false); //$NON-NLS-1$ - if (!(result instanceof ITextEditor)) - throw new MarkerNotPresentableException(markerFile); - return (ITextEditor)result; - } finally { - if (currentEditorId != null) - editorRegistry.setDefaultEditor(markerFile, currentEditorId); - } - } - - private void saveEditor(boolean save) throws CoreException { - if (fEditor == null) - return; - - save= save && fEditor.isDirty(); - if (save) { - IDocumentProvider provider= fEditor.getDocumentProvider(); - IEditorInput input = fEditor.getEditorInput(); - try { - provider.aboutToChange(input); - provider.saveDocument(new NullProgressMonitor(), input, fDocument, true); - fSaved= true; - } finally { - provider.changed(input); - } - } - if (fCloseEditor && !fEditor.isDirty()) - fEditor.close(false); - fEditor= null; - fDocument= null; - fAnnotationModel= null; - fCloseEditor= false; - - } - - private void updateButtons() { - boolean hasNext= hasNextMatch(); - fReplaceNextButton.setEnabled(!fFatalError && fCurrentMatch != null); - fReplaceButton.setEnabled(!fFatalError && fCurrentMatch != null); - fNextButton.setEnabled(!fFatalError && hasNext); - } - - private void restoreAutoBuildState() { - if (!fAutobuild) - return; - IWorkspace workspace= ResourcesPlugin.getWorkspace(); - IWorkspaceDescription description= workspace.getDescription(); - description.setAutoBuilding(true); - try { - workspace.setDescription(description); - } catch (CoreException e) { - ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.reenable_auto_build_failed")); //$NON-NLS-1$ - return; - } - - ISearchResultView view= SearchPlugin.getSearchResultView(); - if (fSaved && view != null) { - new GlobalBuildAction( - view.getSite().getWorkbenchWindow(), - IncrementalProjectBuilder.INCREMENTAL_BUILD).run(); - } - } - - private String getDialogTitle() { - return SearchMessages.getString("ReplaceDialog.dialog.title"); //$NON-NLS-1$ - } - - private void handleMarkerNotPresentableException(MarkerNotPresentableException e) { - IFile file= e.getFile(); - String message; - if (file == null) { - message= SearchMessages.getString("ReplaceDialog.error.no_file_for_marker"); //$NON-NLS-1$ - } else { - message= SearchMessages.getFormattedString("ReplaceDialog.error.unable_to_open_text_editor", file.getName()); //$NON-NLS-1$ - } - MessageDialog.openError(getParentShell(), getDialogTitle(), message); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcePathSorter.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcePathSorter.java deleted file mode 100644 index 5a058cb1fb7..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcePathSorter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; - -import org.eclipse.search.internal.ui.util.FileLabelProvider; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -/** - * Sorts the search result viewer by the resource path. - */ -public class ResourcePathSorter extends ViewerSorter { - - /* - * Overrides method from ViewerSorter - */ - public int compare(Viewer viewer, Object e1, Object e2) { - String name1= null; - String name2= null; - - if (e1 instanceof ISearchResultViewEntry) - name1= ((ISearchResultViewEntry)e1).getResource().getFullPath().toString(); - if (e2 instanceof ISearchResultViewEntry) - name2= ((ISearchResultViewEntry)e2).getResource().getFullPath().toString(); - if (name1 == null) - name1= ""; //$NON-NLS-1$ - if (name2 == null) - name2= ""; //$NON-NLS-1$ - return getCollator().compare(name1, name2); - } - - /* - * Overrides method from ViewerSorter - */ - public boolean isSorterProperty(Object element, String property) { - return true; - } - - /* - * Overrides method from ViewerSorter - */ - public void sort(Viewer viewer, Object[] elements) { - // Set label provider to show "resource - path" - ISearchResultView view= SearchUI.getSearchResultView(); - if (view != null) { - ILabelProvider labelProvider= view.getLabelProvider(); - if (labelProvider instanceof FileLabelProvider) - ((FileLabelProvider)labelProvider).setOrder(FileLabelProvider.SHOW_PATH_LABEL); - } - super.sort(viewer, elements); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcenameSorter.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcenameSorter.java deleted file mode 100644 index 96c5e53e319..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ResourcenameSorter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; - -import org.eclipse.search.internal.ui.util.FileLabelProvider; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -/** - * Sorts the search result viewer by the resource name. - */ -public class ResourcenameSorter extends ViewerSorter { - - /* - * Overrides method from ViewerSorter - */ - public int compare(Viewer viewer, Object e1, Object e2) { - String name1= null; - String name2= null; - - if (e1 instanceof ISearchResultViewEntry) - name1= ((ISearchResultViewEntry)e1).getResource().getName(); - if (e2 instanceof ISearchResultViewEntry) - name2= ((ISearchResultViewEntry)e2).getResource().getName(); - if (name1 == null) - name1= ""; //$NON-NLS-1$ - if (name2 == null) - name2= ""; //$NON-NLS-1$ - return getCollator().compare(name1, name2); - } - - /* - * Overrides method from ViewerSorter - */ - public boolean isSorterProperty(Object element, String property) { - return true; - } - - /* - * Overrides method from ViewerSorter - */ - public void sort(Viewer viewer, Object[] elements) { - // Set label provider to show "resource - path" - ISearchResultView view= SearchUI.getSearchResultView(); - if (view != null) { - ILabelProvider labelProvider= view.getLabelProvider(); - if (labelProvider instanceof FileLabelProvider) - ((FileLabelProvider)labelProvider).setOrder(FileLabelProvider.SHOW_LABEL_PATH); - } - super.sort(viewer, elements); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchActionGroup.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchActionGroup.java deleted file mode 100644 index 8da2e51406b..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchActionGroup.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 International Business Machines Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ -package org.eclipse.search.internal.ui.text; - -import java.util.List; - -import org.eclipse.core.resources.IFile; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; - -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.actions.OpenWithMenu; -import org.eclipse.ui.dialogs.PropertyDialogAction; - -import org.eclipse.search.ui.IContextMenuConstants; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.ui.SearchManager; -import org.eclipse.search.internal.ui.SearchMessages; - -/** - * Action group that adds the Text search actions to a context menu and - * the global menu bar. - * - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * @since 2.1 - */ -class TextSearchActionGroup extends ActionGroup { - - private ISelectionProvider fSelectionProvider; - private IWorkbenchPage fPage; - private PropertyDialogAction fOpenPropertiesDialog; - - public TextSearchActionGroup(IViewPart part) { - Assert.isNotNull(part); - IWorkbenchPartSite site= part.getSite(); - fSelectionProvider= site.getSelectionProvider(); - fPage= site.getPage(); - fOpenPropertiesDialog= new PropertyDialogAction(site.getShell(), fSelectionProvider); - - ISelection selection= fSelectionProvider.getSelection(); - - if (selection instanceof IStructuredSelection) - fOpenPropertiesDialog.selectionChanged((IStructuredSelection)selection); - else - fOpenPropertiesDialog.selectionChanged(selection); - } - - public void fillContextMenu(IMenuManager menu) { - if (!isTextSearch()) - return; - - // view must exist if we create a context menu for it. - ISearchResultView view= SearchUI.getSearchResultView(); - IStructuredSelection selection= null; - if (getContext().getSelection() instanceof IStructuredSelection) - selection= (IStructuredSelection)getContext().getSelection(); - else - selection= StructuredSelection.EMPTY; - - addOpenWithMenu(menu, selection); - - ReplaceAction replaceAll= new ReplaceAction(view.getSite(), (List)getContext().getInput()); - if (replaceAll.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll); - ReplaceAction replaceSelected= new ReplaceAction(view.getSite(), selection); - if (replaceSelected.isEnabled()) - menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelected); - - if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && selection != null &&fOpenPropertiesDialog.isApplicableForSelection(selection)) - menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog); - } - - private boolean isTextSearch() { - IRunnableWithProgress operation= SearchManager.getDefault().getCurrentSearch().getOperation(); - if (operation instanceof TextSearchOperation) { - String pattern= ((TextSearchOperation)operation).getPattern(); - return pattern != null && pattern.length() > 0; - } - return false; - } - - private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) { - if (selection == null || selection.size() != 1) - return; - - Object o= selection.getFirstElement(); - if (!(o instanceof ISearchResultViewEntry)) - return; - - Object resource= ((ISearchResultViewEntry)o).getResource(); - if (!(resource instanceof IFile)) - return; - - // Create menu - IMenuManager submenu= new MenuManager(SearchMessages.getString("OpenWithMenu.label")); //$NON-NLS-1$ - submenu.add(new OpenWithMenu(fPage, (IFile)resource)); - - // Add the submenu. - menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); - } - - /* (non-Javadoc) - * Method declared in ActionGroup - */ - public void fillActionBars(IActionBars actionBar) { - super.fillActionBars(actionBar); - setGlobalActionHandlers(actionBar); - } - - private void setGlobalActionHandlers(IActionBars actionBars) { - actionBars.setGlobalActionHandler(IWorkbenchActionConstants.PROPERTIES, fOpenPropertiesDialog); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchOperation.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchOperation.java deleted file mode 100644 index 5bf28ad90e5..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchOperation.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; - -import org.eclipse.ui.actions.WorkspaceModifyOperation; - -import org.eclipse.search.internal.core.ISearchScope; -import org.eclipse.search.internal.core.text.TextSearchEngine; -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchPluginImages; - -/** - * An operation to perform a regular text search. - */ -public class TextSearchOperation extends WorkspaceModifyOperation { - - public static final int NO_PRIORITY_CHANGE= -1; - - private IWorkspace fWorkspace; - private String fPattern; - private String fOptions; - private ISearchScope fScope; - private TextSearchResultCollector fCollector; - private IStatus fStatus; - - /** - * Creates a new text search operation. - */ - public TextSearchOperation(IWorkspace workspace, String pattern, String options, - ISearchScope scope, TextSearchResultCollector collector) { - Assert.isNotNull(collector); - fWorkspace= workspace; - fPattern= pattern; - fOptions= options; - fScope= scope; - fCollector= collector; - fCollector.setOperation(this); - } - - /** - * The actual algorithm. - */ - protected void execute(IProgressMonitor monitor) { - fCollector.setProgressMonitor(monitor); - TextSearchEngine engine= new TextSearchEngine(); - fStatus= engine.search(fWorkspace, fPattern, fOptions, fScope, fCollector); - } - - String getSingularLabel() { - if (fPattern == null || fPattern.length() < 1) - return SearchMessages.getFormattedString("FileSearchOperation.singularLabelPostfix", new String[] {fScope.getDescription()}); //$NON-NLS-1$ - else - return SearchMessages.getFormattedString("TextSearchOperation.singularLabelPostfix", new String[] {fPattern, fScope.getDescription()}); //$NON-NLS-1$ - } - - String getPluralLabelPattern() { - if (fPattern == null || fPattern.length() < 1) - return SearchMessages.getFormattedString("FileSearchOperation.pluralLabelPatternPostfix", new String[] {"{0}", fScope.getDescription()}); //$NON-NLS-2$ //$NON-NLS-1$ - else - return SearchMessages.getFormattedString("TextSearchOperation.pluralLabelPatternPostfix", new String[] {fPattern, "{0}", fScope.getDescription()}); //$NON-NLS-2$ //$NON-NLS-1$ - } - - ImageDescriptor getImageDescriptor() { - return SearchPluginImages.DESC_OBJ_TSEARCH_DPDN; - } - - IStatus getStatus() { - return fStatus; - } - - String getPattern() { - return fPattern; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java deleted file mode 100644 index 1089459a5ea..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java +++ /dev/null @@ -1,583 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.dialogs.DialogPage; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; - -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.model.IWorkbenchAdapter; - -import org.eclipse.search.ui.ISearchPage; -import org.eclipse.search.ui.ISearchPageContainer; -import org.eclipse.search.ui.ISearchResultViewEntry; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.core.text.TextSearchScope; -import org.eclipse.search.internal.ui.ISearchHelpContextIds; -import org.eclipse.search.internal.ui.ScopePart; -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.internal.ui.util.ExceptionHandler; -import org.eclipse.search.internal.ui.util.FileTypeEditor; -import org.eclipse.search.internal.ui.util.RowLayouter; -import org.eclipse.search.internal.ui.util.SWTUtil; - -public class TextSearchPage extends DialogPage implements ISearchPage { - - public static final String EXTENSION_POINT_ID= "org.eclipse.search.internal.ui.text.TextSearchPage"; //$NON-NLS-1$ - - // Dialog store id constants - private final static String PAGE_NAME= "TextSearchPage"; //$NON-NLS-1$ - private final static String STORE_CASE_SENSITIVE= PAGE_NAME + "CASE_SENSITIVE"; //$NON-NLS-1$ - - private static List fgPreviousSearchPatterns= new ArrayList(20); - - private IDialogSettings fDialogSettings; - private boolean fFirstTime= true; - private boolean fIsCaseSensitive; - - private Combo fPattern; - private Button fIgnoreCase; - private Combo fExtensions; - - private ISearchPageContainer fContainer; - private FileTypeEditor fFileTypeEditor; - - - private static class SearchPatternData { - boolean ignoreCase; - String textPattern; - Set fileNamePatterns; - int scope; - IWorkingSet[] workingSets; - - public SearchPatternData(String textPattern, boolean ignoreCase, Set fileNamePatterns, int scope, IWorkingSet[] workingSets) { - this.ignoreCase= ignoreCase; - this.textPattern= textPattern; - this.fileNamePatterns= fileNamePatterns; - this.scope= scope; - this.workingSets= workingSets; - } - } - //---- Action Handling ------------------------------------------------ - - public boolean performAction() { - - SearchUI.activateSearchResultView(); - - SearchPatternData patternData= getPatternData(); - if (patternData.fileNamePatterns == null || fExtensions.getText().length() <= 0) { - patternData.fileNamePatterns= new HashSet(1); - patternData.fileNamePatterns.add("*"); //$NON-NLS-1$ - } - - // Setup search scope - TextSearchScope scope= null; - switch (getContainer().getSelectedScope()) { - case ISearchPageContainer.WORKSPACE_SCOPE: - scope= TextSearchScope.newWorkspaceScope(); - break; - case ISearchPageContainer.SELECTION_SCOPE: - scope= getSelectedResourcesScope(); - break; - case ISearchPageContainer.WORKING_SET_SCOPE: - IWorkingSet[] workingSets= getContainer().getSelectedWorkingSets(); - String desc= SearchMessages.getFormattedString("WorkingSetScope", ScopePart.toString(workingSets)); //$NON-NLS-1$ - scope= new TextSearchScope(desc, workingSets); - } - scope.addExtensions(patternData.fileNamePatterns); - - TextSearchResultCollector collector= new TextSearchResultCollector(); - - TextSearchOperation op= new TextSearchOperation( - SearchPlugin.getWorkspace(), - patternData.textPattern, - getSearchOptions(), - scope, - collector); - - IRunnableContext context= null; - context= getContainer().getRunnableContext(); - - Shell shell= fPattern.getShell(); - if (context == null) - context= new ProgressMonitorDialog(shell); - - try { - context.run(true, true, op); - } catch (InvocationTargetException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.search.title"),SearchMessages.getString("Search.Error.search.message")); //$NON-NLS-2$ //$NON-NLS-1$ - return false; - } catch (InterruptedException e) { - return false; - } - IStatus status= op.getStatus(); - if (status != null && !status.isOK()) { - String title= SearchMessages.getString("Search.Problems.title"); //$NON-NLS-1$ - ErrorDialog.openError(getShell(), title, null, status); //$NON-NLS-1$ - } - return true; - } - - private String getPattern() { - return fPattern.getText(); - } - - /** - * Return search pattern data and update previous searches. - * An existing entry will be updated. - */ - private SearchPatternData getPatternData() { - SearchPatternData match= null; - String textPattern= fPattern.getText(); - int i= fgPreviousSearchPatterns.size() - 1; - while (i >= 0) { - match= (SearchPatternData)fgPreviousSearchPatterns.get(i); - if (textPattern.equals(match.textPattern)) - break; - i--; - }; - if (i >= 0) { - match.ignoreCase= ignoreCase(); - match.textPattern= getPattern(); - match.fileNamePatterns= getExtensions(); - match.scope= getContainer().getSelectedScope(); - match.workingSets= getContainer().getSelectedWorkingSets(); - // remove - will be added last (see below) - fgPreviousSearchPatterns.remove(match); - } else { - match= new SearchPatternData( - getPattern(), - ignoreCase(), - getExtensions(), - getContainer().getSelectedScope(), - getContainer().getSelectedWorkingSets()); - } - fgPreviousSearchPatterns.add(match); - return match; - } - - private String[] getPreviousExtensions() { - List extensions= new ArrayList(fgPreviousSearchPatterns.size()); - for (int i= fgPreviousSearchPatterns.size() -1 ; i >= 0; i--) { - SearchPatternData data= (SearchPatternData)fgPreviousSearchPatterns.get(i); - String text= FileTypeEditor.typesToString(data.fileNamePatterns); - if (!extensions.contains(text)) - extensions.add(text); - } - return (String[])extensions.toArray(new String[extensions.size()]); - } - - private String[] getPreviousSearchPatterns() { - int size= fgPreviousSearchPatterns.size(); - String [] patterns= new String[size]; - for (int i= 0; i < size; i++) - patterns[i]= ((SearchPatternData) fgPreviousSearchPatterns.get(size - 1 - i)).textPattern; - return patterns; - } - - private String getSearchOptions() { - StringBuffer result= new StringBuffer(); - if (!ignoreCase()) - result.append("i"); //$NON-NLS-1$ - return result.toString(); - } - - private Display getTargetDisplay() { - return fPattern.getDisplay(); - } - - private Set getExtensions() { - return fFileTypeEditor.getFileTypes(); - } - - private boolean ignoreCase() { - return fIgnoreCase.getSelection(); - } - - /* - * Implements method from IDialogPage - */ - public void setVisible(boolean visible) { - if (visible && fPattern != null) { - if (fFirstTime) { - fFirstTime= false; - // Set item and text here to prevent page from resizing - fPattern.setItems(getPreviousSearchPatterns()); - fExtensions.setItems(getPreviousExtensions()); - initializePatternControl(); - } - fPattern.setFocus(); - getContainer().setPerformActionEnabled(getContainer().hasValidScope()); - } - super.setVisible(visible); - } - - //---- Widget creation ------------------------------------------------ - - /** - * Creates the page's content. - */ - public void createControl(Composite parent) { - initializeDialogUnits(parent); - readConfiguration(); - - GridData gd; - Composite result= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(3, false); - layout.horizontalSpacing= 10; - result.setLayout(layout); - result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - RowLayouter layouter= new RowLayouter(layout.numColumns); - gd= new GridData(); - gd.horizontalAlignment= gd.FILL; - gd.verticalAlignment= gd.VERTICAL_ALIGN_BEGINNING | gd.VERTICAL_ALIGN_FILL; - - layouter.setDefaultGridData(gd, 0); - layouter.setDefaultGridData(gd, 1); - layouter.setDefaultGridData(gd, 2); - layouter.setDefaultSpan(); - - layouter.perform(createTextSearchComposite(result)); - - // Vertical filler - Label filler= new Label(result, SWT.LEFT); - gd= new GridData(GridData.BEGINNING | GridData.VERTICAL_ALIGN_FILL); - gd.heightHint= convertHeightInCharsToPixels(1) / 3; - filler.setLayoutData(gd); - layouter.perform(new Control[] {filler}, 3); - - layouter.perform(createFileNamePatternComposite(result)); - - setControl(result); - - WorkbenchHelp.setHelp(result, ISearchHelpContextIds.TEXT_SEARCH_PAGE); - } - - private Control createTextSearchComposite(Composite group) { - GridData gd; - Label label; - - // Info text - label= new Label(group, SWT.LEFT); - label.setText(SearchMessages.getString("SearchPage.containingText.text")); //$NON-NLS-1$ - gd= new GridData(GridData.BEGINNING); - gd.horizontalSpan= 3; - label.setLayoutData(gd); - - // Pattern combo - fPattern= new Combo(group, SWT.SINGLE | SWT.BORDER); - // Not done here to prevent page from resizing - // fPattern.setItems(getPreviousSearchPatterns()); - fPattern.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - getContainer().setPerformActionEnabled(true); - } - }); - fPattern.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleWidgetSelected(); - } - }); - gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); - gd.horizontalSpan= 2; - fPattern.setLayoutData(gd); - - fIgnoreCase= new Button(group, SWT.CHECK); - fIgnoreCase.setText(SearchMessages.getString("SearchPage.caseSensitive")); //$NON-NLS-1$ - gd= new GridData(GridData.HORIZONTAL_ALIGN_END); - fIgnoreCase.setLayoutData(gd); - fIgnoreCase.setSelection(!fIsCaseSensitive); - fIgnoreCase.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - fIsCaseSensitive= !fIgnoreCase.getSelection(); - writeConfiguration(); - } - }); - - // Text line which explains the special characters - label= new Label(group, SWT.LEFT); - label.setText(SearchMessages.getString("SearchPage.containingText.hint")); //$NON-NLS-1$ - gd= new GridData(GridData.BEGINNING); - gd.horizontalSpan= 3; - label.setLayoutData(gd); - - return group; - } - - private void handleWidgetSelected() { - if (fPattern.getSelectionIndex() < 0) - return; - int index= fgPreviousSearchPatterns.size() - 1 - fPattern.getSelectionIndex(); - SearchPatternData patternData= (SearchPatternData) fgPreviousSearchPatterns.get(index); - if (patternData == null || !fPattern.getText().equals(patternData.textPattern)) - return; - fIgnoreCase.setSelection(patternData.ignoreCase); - fPattern.setText(patternData.textPattern); - fFileTypeEditor.setFileTypes(patternData.fileNamePatterns); - if (patternData.workingSets != null) - getContainer().setSelectedWorkingSets(patternData.workingSets); - else - getContainer().setSelectedScope(patternData.scope); - } - - private void initializePatternControl() { - ISelection selection= getSelection(); - String text= ""; //$NON-NLS-1$ - String extension= null; - if (selection instanceof ITextSelection) { - ITextSelection textSelection= (ITextSelection)getSelection(); - text= textSelection.getText(); - } else { - IResource resource= null; - Object item= null; - if (selection instanceof IStructuredSelection) - item= ((IStructuredSelection)selection).getFirstElement(); - if (item instanceof IResource) { - resource= (IResource)item; - text= resource.getName(); - } - else if (item instanceof ISearchResultViewEntry) { - IMarker marker= (IMarker)((ISearchResultViewEntry)item).getSelectedMarker(); - resource= marker.getResource(); - try { - text= (String)marker.getAttribute(SearchUI.LINE); - } catch (CoreException ex) { - ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.markerAttributeAccess.title"), SearchMessages.getString("Search.Error.markerAttributeAccess.message")); //$NON-NLS-2$ //$NON-NLS-1$ - text= ""; //$NON-NLS-1$ - } - } else if (item instanceof IAdaptable) { - Object adapter= ((IAdaptable)item).getAdapter(IWorkbenchAdapter.class); - if (adapter instanceof IWorkbenchAdapter) - text= ((IWorkbenchAdapter)adapter).getLabel(item); - - adapter= ((IAdaptable)item).getAdapter(IResource.class); - if (adapter instanceof IResource) { - resource= (IResource)adapter; - if (text == null) // keep text, if provided by workbench adapter - text= resource.getName(); - } - } - if (resource instanceof IFile ) { - extension= resource.getFileExtension(); - if (extension == null) - extension= resource.getName(); - else - extension= "*." + extension; //$NON-NLS-1$ - } - else - extension= "*"; //$NON-NLS-1$ - } - fPattern.setText(insertEscapeChars(text)); - - if (getPreviousExtensions().length > 0) - fExtensions.setText(getPreviousExtensions()[0]); - else { - if (extension == null) - extension= getExtensionFromEditor(); - if (extension != null) - fExtensions.setText(extension); - } - } - - private String insertEscapeChars(String text) { - if (text == null || text.equals("")) //$NON-NLS-1$ - return ""; //$NON-NLS-1$ - StringBuffer sbIn= new StringBuffer(text); - BufferedReader reader= new BufferedReader(new StringReader(text)); - int lengthOfFirstLine= 0; - try { - lengthOfFirstLine= reader.readLine().length(); - } catch (IOException ex) { - return ""; //$NON-NLS-1$ - } - StringBuffer sbOut= new StringBuffer(lengthOfFirstLine + 5); - int i= 0; - while (i < lengthOfFirstLine) { - char ch= sbIn.charAt(i); - if (ch == '*' || ch == '?' || ch == '\\') - sbOut.append("\\"); //$NON-NLS-1$ - sbOut.append(ch); - i= i+1; - }; - return sbOut.toString(); - } - - private String getExtensionFromEditor() { - IEditorPart ep= SearchPlugin.getActivePage().getActiveEditor(); - if (ep != null) { - Object elem= ep.getEditorInput(); - if (elem instanceof IFileEditorInput) { - String extension= ((IFileEditorInput)elem).getFile().getFileExtension(); - if (extension == null) - return ((IFileEditorInput)elem).getFile().getName(); - else - return "*." + extension; //$NON-NLS-1$ - } - } - return null; - } - - private Control createFileNamePatternComposite(Composite group) { - GridData gd; - - // Line with label, combo and button - Label label= new Label(group, SWT.LEFT); - label.setText(SearchMessages.getString("SearchPage.fileNamePatterns.text")); //$NON-NLS-1$ - gd= new GridData(GridData.BEGINNING); - gd.horizontalSpan= 3; - label.setLayoutData(gd); - - fExtensions= new Combo(group, SWT.SINGLE | SWT.BORDER); - fExtensions.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - getContainer().setPerformActionEnabled(getContainer().hasValidScope()); - } - }); - gd= new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); - gd.horizontalSpan= 2; - fExtensions.setLayoutData(gd); - - Button button= new Button(group, SWT.PUSH); - button.setText(SearchMessages.getString("SearchPage.browse")); //$NON-NLS-1$ - gd= new GridData(GridData.HORIZONTAL_ALIGN_END); - button.setLayoutData(gd); - SWTUtil.setButtonDimensionHint(button); - fFileTypeEditor= new FileTypeEditor( - SearchPlugin.getDefault().getWorkbench().getEditorRegistry(), - fExtensions, button); - - // Text line which explains the special characters - label= new Label(group, SWT.LEFT); - label.setText(SearchMessages.getString("SearchPage.fileNamePatterns.hint")); //$NON-NLS-1$ - gd= new GridData(GridData.BEGINNING); - gd.horizontalSpan= 3; - label.setLayoutData(gd); - - return group; - } - - public boolean isValid() { - return true; - } - - /** - * Sets the search page's container. - */ - public void setContainer(ISearchPageContainer container) { - fContainer= container; - } - - /** - * Returns the search page's container. - */ - private ISearchPageContainer getContainer() { - return fContainer; - } - - /** - * Returns the current active selection. - */ - private ISelection getSelection() { - return fContainer.getSelection(); - } - - private TextSearchScope getSelectedResourcesScope() { - TextSearchScope scope= new TextSearchScope(SearchMessages.getString("SelectionScope")); //$NON-NLS-1$ - if (getSelection() instanceof IStructuredSelection && !getSelection().isEmpty()) { - Iterator iter= ((IStructuredSelection)getSelection()).iterator(); - while (iter.hasNext()) { - Object selection= iter.next(); - - //Unpack search result entry - if (selection instanceof ISearchResultViewEntry) - selection= ((ISearchResultViewEntry)selection).getGroupByKey(); - - if (selection instanceof IResource) - scope.add((IResource)selection); - else if (selection instanceof IAdaptable) { - IResource resource= (IResource)((IAdaptable)selection).getAdapter(IResource.class); - if (resource != null) - scope.add(resource); - } - } - } - return scope; - } - - //--------------- Configuration handling -------------- - - /** - * Returns the page settings for this Java search page. - * - * @return the page settings to be used - */ - private IDialogSettings getDialogSettings() { - IDialogSettings settings= SearchPlugin.getDefault().getDialogSettings(); - fDialogSettings= settings.getSection(PAGE_NAME); - if (fDialogSettings == null) - fDialogSettings= settings.addNewSection(PAGE_NAME); - return fDialogSettings; - } - - /** - * Initializes itself from the stored page settings. - */ - private void readConfiguration() { - IDialogSettings s= getDialogSettings(); - fIsCaseSensitive= s.getBoolean(STORE_CASE_SENSITIVE); - } - - /** - * Stores it current configuration in the dialog store. - */ - private void writeConfiguration() { - IDialogSettings s= getDialogSettings(); - s.put(STORE_CASE_SENSITIVE, fIsCaseSensitive); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java deleted file mode 100644 index 635e5b1122b..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchResultCollector.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.text; - -import java.text.MessageFormat; -import java.util.HashMap; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.ui.actions.ActionGroup; - -import org.eclipse.search.ui.IActionGroupFactory; -import org.eclipse.search.ui.ISearchResultView; -import org.eclipse.search.ui.SearchUI; - -import org.eclipse.search.internal.core.text.ITextSearchResultCollector; -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.util.FileLabelProvider; - -public class TextSearchResultCollector implements ITextSearchResultCollector { - - private static final String MATCH= SearchMessages.getString("SearchResultCollector.match"); //$NON-NLS-1$ - private static final String MATCHES= SearchMessages.getString("SearchResultCollector.matches"); //$NON-NLS-1$ - private static final String DONE= SearchMessages.getString("SearchResultCollector.done"); //$NON-NLS-1$ - - private IProgressMonitor fMonitor; - private ISearchResultView fView; - private TextSearchOperation fOperation; - private int fMatchCount= 0; - private Integer[] fMessageFormatArgs= new Integer[1]; - private long fLastUpdateTime; - - - private static class TextSearchActionGroupFactory implements IActionGroupFactory { - public ActionGroup createActionGroup(ISearchResultView part) { - return new TextSearchActionGroup(part); - } - } - - /** - * Returns the progress monitor used to setup and report progress. - */ - public IProgressMonitor getProgressMonitor() { - return fMonitor; - } - - void setProgressMonitor(IProgressMonitor pm) { - fMonitor= pm; - } - - /** - * Called before the actual search starts. - */ - public void aboutToStart() throws CoreException { - fView= SearchUI.getSearchResultView(); - fMatchCount= 0; - fLastUpdateTime= 0; - if (fView != null) { - fView.searchStarted( - new TextSearchActionGroupFactory(), - fOperation.getSingularLabel(), - fOperation.getPluralLabelPattern(), - fOperation.getImageDescriptor(), - TextSearchPage.EXTENSION_POINT_ID, - new FileLabelProvider(FileLabelProvider.SHOW_LABEL_PATH), - new GotoMarkerAction(), - new GroupByKeyComputer(), - fOperation); - } - } - - /** - * Accepts the given search result. - */ - public void accept(final IResource resource, String line, int start, int length, final int lineNumber) throws CoreException { - IMarker marker= resource.createMarker(SearchUI.SEARCH_MARKER); - HashMap attributes= new HashMap(4); - attributes.put(SearchUI.LINE, line); - attributes.put(IMarker.CHAR_START, new Integer(start)); - attributes.put(IMarker.CHAR_END, new Integer(start + length)); - attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber)); - marker.setAttributes(attributes); - - String description= resource.getFullPath().lastSegment(); - if (description == null) - description= ""; //$NON-NLS-1$ - - fView.addMatch(description, resource, resource, marker); - - fMatchCount++; - - if (!getProgressMonitor().isCanceled() && System.currentTimeMillis() - fLastUpdateTime > 1000) { - getProgressMonitor().subTask(getFormattedMatchesString(fMatchCount)); - fLastUpdateTime= System.currentTimeMillis(); - } - } - - /** - * Called when the search has ended. - */ - public void done() { - if (!getProgressMonitor().isCanceled()) { - String matchesString= getFormattedMatchesString(fMatchCount); - getProgressMonitor().setTaskName(MessageFormat.format(DONE, new String[]{matchesString})); - } - - if (fView != null) - fView.searchFinished(); - - // Cut no longer unused references because the collector might be re-used - fView= null; - fMonitor= null; - } - - void setOperation(TextSearchOperation operation) { - fOperation= operation; - } - - private String getFormattedMatchesString(int count) { - if (fMatchCount == 1) - return MATCH; - fMessageFormatArgs[0]= new Integer(count); - return MessageFormat.format(MATCHES, fMessageFormatArgs); - - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExceptionHandler.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExceptionHandler.java deleted file mode 100644 index c8c1dd5f1f6..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExceptionHandler.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.io.StringWriter; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import org.eclipse.search.internal.ui.SearchMessages; -import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.ui.SearchUI; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.MessageDialog; - -/** - * The default exception handler shows an error dialog when one of its handle methods - * is called. If the passed exception is a <code>CoreException</code> an error dialog - * pops up showing the exception's status information. For a <code>InvocationTargetException</code> - * a normal message dialog pops up showing the exception's message. Additionally the exception - * is written to the platform log. - */ -public class ExceptionHandler { - - private static ExceptionHandler fgInstance= new ExceptionHandler(); - - /** - * Logs the given exception using the platform's logging mechanism. The exception is - * logged as an error with the error code <code>JavaStatusConstants.INTERNAL_ERROR</code>. - */ - public static void log(Throwable t, String message) { - SearchPlugin.log(new Status(IStatus.ERROR, SearchUI.PLUGIN_ID, IStatus.ERROR, message, t)); - } - - /** - * Handles the given <code>CoreException</code>. The workbench shell is used as a parent - * for the dialog window. - * - * @param e the <code>CoreException</code> to be handled - * @param title the dialog window's window title - * @param message message to be displayed by the dialog window - */ - public static void handle(CoreException e, String title, String message) { - handle(e, SearchPlugin.getActiveWorkbenchShell(), title, message); - } - - /** - * Handles the given <code>CoreException</code>. - * - * @param e the <code>CoreException</code> to be handled - * @param parent the dialog window's parent shell - * @param title the dialog window's window title - * @param message message to be displayed by the dialog window - */ - public static void handle(CoreException e, Shell parent, String title, String message) { - fgInstance.perform(e, parent, title, message); - } - - /** - * Handles the given <code>InvocationTargetException</code>. The workbench shell is used - * as a parent for the dialog window. - * - * @param e the <code>InvocationTargetException</code> to be handled - * @param title the dialog window's window title - * @param message message to be displayed by the dialog window - */ - public static void handle(InvocationTargetException e, String title, String message) { - handle(e, SearchPlugin.getActiveWorkbenchShell(), title, message); - } - - /** - * Handles the given <code>InvocationTargetException</code>. - * - * @param e the <code>InvocationTargetException</code> to be handled - * @param parent the dialog window's parent shell - * @param title the dialog window's window title - * @param message message to be displayed by the dialog window - */ - public static void handle(InvocationTargetException e, Shell parent, String title, String message) { - fgInstance.perform(e, parent, title, message); - } - - //---- Hooks for subclasses to control exception handling ------------------------------------ - - protected void perform(CoreException e, Shell shell, String title, String message) { - IStatus status= e.getStatus(); - if (status != null) { - ErrorDialog.openError(shell, title, message, status); - } else { - displayMessageDialog(e, e.getMessage(), shell, title, message); - } - } - - protected void perform(InvocationTargetException e, Shell shell, String title, String message) { - Throwable target= e.getTargetException(); - if (target instanceof CoreException) { - perform((CoreException)target, shell, title, message); - } else { - if (e.getMessage() != null && e.getMessage().length() > 0) { - displayMessageDialog(e, e.getMessage(), shell, title, message); - } else { - displayMessageDialog(e, target.getMessage(), shell, title, message); - } - } - } - - //---- Helper methods ----------------------------------------------------------------------- - - public static void displayMessageDialog(Throwable t, Shell shell, String title, String message) { - fgInstance.displayMessageDialog(t, t.getMessage(), shell, title, message); - } - - public static void displayMessageDialog(Throwable t, String title, String message) { - displayMessageDialog(t, SearchPlugin.getActiveWorkbenchShell(), title, message); - } - - private void displayMessageDialog(Throwable t, String exceptionMessage, Shell shell, String title, String message) { - StringWriter msg= new StringWriter(); - if (message != null) { - msg.write(message); - msg.write("\n\n"); //$NON-NLS-1$ - } - if (exceptionMessage == null || exceptionMessage.length() == 0) - msg.write(SearchMessages.getString("ExceptionDialog.seeErrorLogMessage")); //$NON-NLS-1$ - else - msg.write(exceptionMessage); - MessageDialog.openError(shell, title, msg.toString()); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java deleted file mode 100644 index e17884a7f08..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.dialogs.ControlEnableState; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.operation.ModalContext; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.wizard.ProgressMonitorPart; - -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.search.internal.ui.SearchMessages; - - -public abstract class ExtendedDialogWindow extends Dialog implements IRunnableContext { - - private Control fContents; - private Button fCancelButton; - private Button fSearchButton; - - private String fPerformActionLabel= JFaceResources.getString("finish"); //$NON-NLS-1$ - - // The number of long running operation executed from the dialog. - private long fActiveRunningOperations; - private boolean fOperationCancelableState; - - // The progress monitor - private ProgressMonitorPart fProgressMonitorPart; - private MessageDialog fWindowClosingDialog; - private static int PROGRESS_INDICATOR_HEIGHT= 12; - private static final String FOCUS_CONTROL= "focusControl"; //$NON-NLS-1$ - private Cursor fWaitCursor; - private Cursor fArrowCursor; - - - public ExtendedDialogWindow(Shell shell) { - super(shell); - } - - //---- Hooks to reimplement in subclasses ----------------------------------- - - /** - * Hook called when the user has pressed the button to perform - * the dialog's action. If the method returns <code>false</code> - * the dialog stays open. Otherwise the dialog is going to be closed. - */ - protected boolean performAction() { - return true; - } - - /** - * Hook called when the user has pressed the button to cancel - * the dialog. If the method returns <code>false</code> the dialog - * stays open. Otherwise the dialog is going to be closed. - */ - protected boolean performCancel() { - return true; - } - - //---- UI creation ---------------------------------------------------------- - - /** - * Create the page area. - */ - protected abstract Control createPageArea(Composite parent); - - /** - * Add buttons to the dialog's button bar. - * - * Subclasses may override. - * - * @param parent the button bar composite - */ - protected void createButtonsForButtonBar(Composite parent) { - - fSearchButton= createButton(parent, IDialogConstants.FINISH_ID, fPerformActionLabel, true); - fCancelButton= createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); - } - - /** - * Creates the layout of the extended dialog window. - */ - protected Control createDialogArea(Composite parent) { - Composite result= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.marginWidth= 0; - layout.marginHeight= 0; - layout.horizontalSpacing= 0; - layout.verticalSpacing= 0; - result.setLayout(layout); - result.setLayoutData(new GridData(GridData.FILL_BOTH)); - - fContents= createPageArea(result); - - // Insert a progress monitor - GridLayout pmlayout= new GridLayout(); - pmlayout.numColumns= 1; - fProgressMonitorPart= new ProgressMonitorPart(result, pmlayout, SWT.DEFAULT); - fProgressMonitorPart.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fProgressMonitorPart.setVisible(false); - - - Label separator= new Label(result, SWT.SEPARATOR | SWT.HORIZONTAL); - separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - return result; - } - - - protected void buttonPressed(int buttonId) { - switch (buttonId) { - case IDialogConstants.FINISH_ID: - if (performAction()) - close(); - break; - case IDialogConstants.CANCEL_ID: - if (fActiveRunningOperations == 0) - close(); - break; - } - } - - //---- Setters and Getters -------------------------------------------------- - - /** - * Sets the label text of the perform action button. - */ - public void setPerformActionLabel(String label) { - fPerformActionLabel= label; - } - - /** - * Set the enable state of the perform action button. - */ - public void setPerformActionEnabled(boolean state) { - if (fSearchButton != null) - fSearchButton.setEnabled(state); - } - - //---- Operation stuff ------------------------------------------------------ - - /** - * Runs the given <code>IRunnableWithProgress</code> with the progress monitor for this - * wizard dialog. - * @param fork if true, it is run in a separate thread - * @param cancelable specifies whether to enable the cancel button or not - * @param runnable the runnable to run - */ - public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { - // The operation can only be canceled if it is executed in a separate thread. - // Otherwise the UI is blocked anyway. - Object state= null; - try { - fActiveRunningOperations++; - state= aboutToStart(fork && cancelable); - ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay()); - } finally { - if (state != null) - stopped(state); - fActiveRunningOperations--; - } - } - - /** - * Returns the progress monitor. If the wizard dialog doesn't - * have a progress monitor <code>null</code> is returned. - */ - protected IProgressMonitor getProgressMonitor() { - return fProgressMonitorPart; - } - - /** - * About to start a long running operation tiggered through - * the wizard. So show the progress monitor and disable - * the wizard. - * @return The saved UI state. - */ - protected synchronized Object aboutToStart(boolean enableCancelButton) { - HashMap savedState= null; - fOperationCancelableState= enableCancelButton; - Shell shell= getShell(); - if (shell != null) { - Display d= shell.getDisplay(); - - // Save focus control - Control focusControl= d.getFocusControl(); - if (focusControl != null && focusControl.getShell() != shell) - focusControl= null; - - // Set the busy cursor to all shells. - fWaitCursor= new Cursor(d, SWT.CURSOR_WAIT); - setDisplayCursor(d, fWaitCursor); - - // Set the arrow cursor to the cancel component. - fArrowCursor= new Cursor(d, SWT.CURSOR_ARROW); - fCancelButton.setCursor(fArrowCursor); - - // Deactivate shell - savedState= saveUIState(enableCancelButton); - if (focusControl != null) - savedState.put(FOCUS_CONTROL, focusControl); - - // Attach the progress monitor part to the cancel button - fProgressMonitorPart.attachToCancelComponent(fCancelButton); - fProgressMonitorPart.setVisible(true); - } - - return savedState; - } - - /** - * A long running operation triggered through the wizard - * was stopped either by user input or by normal end. - * @param savedState The saveState returned by <code>aboutToStart</code>. - * @see #aboutToStart(boolean) - */ - protected synchronized void stopped(Object savedState) { - Assert.isTrue( savedState instanceof HashMap); - Shell shell= getShell(); - if (shell != null) { - - fProgressMonitorPart.setVisible(false); - fProgressMonitorPart.removeFromCancelComponent(fCancelButton); - - HashMap state= (HashMap)savedState; - restoreUIState(state); - - setDisplayCursor(shell.getDisplay(), null); - fCancelButton.setCursor(null); - fWaitCursor.dispose(); - fWaitCursor= null; - fArrowCursor.dispose(); - fArrowCursor= null; - Control focusControl= (Control)state.get(FOCUS_CONTROL); - if (focusControl != null && ! focusControl.isDisposed()) - focusControl.setFocus(); - } - } - - private void asyncSetOperationCancelButtonEnabled(final boolean b) { - Shell shell= getShell(); - if (shell != null) { - shell.getDisplay().asyncExec(new Runnable() { - public void run() { - setOperationCancelButtonEnabled(b); - } - }); - } - } - - private void setOperationCancelButtonEnabled(boolean b) { - if (fActiveRunningOperations > 0) { - fCancelButton.setEnabled(b); - } - } - - private void setDisplayCursor(Display d, Cursor c) { - Shell[] shells= d.getShells(); - for (int i= 0; i < shells.length; i++) - shells[i].setCursor(c); - } - - //---- UI state save and restoring --------------------------------------------- - - private void restoreUIState(HashMap state) { - restoreEnableState(fCancelButton, state, "cancel"); //$NON-NLS-1$ - restoreEnableState(fSearchButton, state, "search"); //$NON-NLS-1$ - ControlEnableState pageState= (ControlEnableState)state.get("tabForm"); //$NON-NLS-1$ - pageState.restore(); - } - - /** - * Restores the enable state of the given control. - * @private - */ - protected void restoreEnableState(Control w, HashMap h, String key) { - if (!w.isDisposed()) { - Boolean b= (Boolean)h.get(key); - if (b != null) - w.setEnabled(b.booleanValue()); - } - } - - private HashMap saveUIState(boolean keepCancelEnabled) { - HashMap savedState= new HashMap(10); - saveEnableStateAndSet(fCancelButton, savedState, "cancel", keepCancelEnabled); //$NON-NLS-1$ - saveEnableStateAndSet(fSearchButton, savedState, "search", false); //$NON-NLS-1$ - savedState.put("tabForm", ControlEnableState.disable(fContents)); //$NON-NLS-1$ - - return savedState; - } - - private void saveEnableStateAndSet(Control w, HashMap h, String key, boolean enabled) { - if (!w.isDisposed()) { - h.put(key, new Boolean(w.isEnabled())); - w.setEnabled(enabled); - } - } - - protected void handleShellCloseEvent() { - if (okToClose()) - super.handleShellCloseEvent(); - } - - /** - * The dialog is going to be closed. Check if there is a running - * operation. If so, post an alert saying that the wizard can't - * be closed. - */ - public boolean okToClose() { - if (fActiveRunningOperations > 0) { - synchronized (this) { - fWindowClosingDialog= createClosingDialog(); - } - fWindowClosingDialog.open(); - synchronized (this) { - fWindowClosingDialog= null; - } - return false; - } - return true; - } - - private MessageDialog createClosingDialog() { - MessageDialog result= - new MessageDialog( - getShell(), - SearchMessages.getString("SearchDialogClosingDialog.title"), //$NON-NLS-1$ - null, - SearchMessages.getString("SearchDialogClosingDialog.message"), //$NON-NLS-1$ - MessageDialog.QUESTION, - new String[] {IDialogConstants.OK_LABEL}, - 0); - return result; - } - - /** - * Returns the cancel component that is to be used to cancel - * a long running operation. - */ - protected Control getCancelComponent() { - return fCancelButton; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java deleted file mode 100644 index 186b1487660..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.text.MessageFormat; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.jface.viewers.ILabelDecorator; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.LabelProvider; - -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.model.WorkbenchLabelProvider; - -import org.eclipse.search.ui.ISearchResultViewEntry; - -import org.eclipse.search.internal.ui.SearchMessages; - - -public class FileLabelProvider extends LabelProvider { - - public static final int SHOW_LABEL= 1; - public static final int SHOW_LABEL_PATH= 2; - public static final int SHOW_PATH_LABEL= 3; - public static final int SHOW_PATH= 4; - - private static final String fgSeparatorFormat= SearchMessages.getString("FileLabelProvider.dashSeparated"); //$NON-NLS-1$ - - private WorkbenchLabelProvider fLabelProvider; - private ILabelDecorator fDecorator; - - private int fOrder; - private String[] fArgs= new String[2]; - - public FileLabelProvider(int orderFlag) { - fDecorator= PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); - fLabelProvider= new WorkbenchLabelProvider(); - fOrder= orderFlag; - } - - public void setOrder(int orderFlag) { - fOrder= orderFlag; - } - - public String getText(Object element) { - if (!(element instanceof ISearchResultViewEntry)) - return ""; //$NON-NLS-1$ - - IResource resource= ((ISearchResultViewEntry) element).getResource(); - String text= null; - - if (resource == null || !resource.exists()) - text= SearchMessages.getString("SearchResultView.removed_resource"); //$NON-NLS-1$ - - else { - IPath path= resource.getFullPath().removeLastSegments(1); - if (path.getDevice() == null) - path= path.makeRelative(); - if (fOrder == SHOW_LABEL || fOrder == SHOW_LABEL_PATH) { - text= fLabelProvider.getText(resource); - if (path != null && fOrder == SHOW_LABEL_PATH) { - fArgs[0]= text; - fArgs[1]= path.toString(); - text= MessageFormat.format(fgSeparatorFormat, fArgs); - } - } else { - if (path != null) - text= path.toString(); - else - text= ""; //$NON-NLS-1$ - if (fOrder == SHOW_PATH_LABEL) { - fArgs[0]= text; - fArgs[1]= fLabelProvider.getText(resource); - text= MessageFormat.format(fgSeparatorFormat, fArgs); - } - } - } - - // Do the decoration - if (fDecorator != null) { - String decoratedText= fDecorator.decorateText(text, resource); - if (decoratedText != null) - return decoratedText; - } - return text; - } - - public Image getImage(Object element) { - if (!(element instanceof ISearchResultViewEntry)) - return null; //$NON-NLS-1$ - - IResource resource= ((ISearchResultViewEntry) element).getResource(); - Image image= fLabelProvider.getImage(resource); - if (fDecorator != null) { - Image decoratedImage= fDecorator.decorateImage(image, resource); - if (decoratedImage != null) - return decoratedImage; - } - return image; - } - - public void dispose() { - super.dispose(); - fLabelProvider.dispose(); - } - - public boolean isLabelProperty(Object element, String property) { - return fLabelProvider.isLabelProperty(element, property); - } - - public void removeListener(ILabelProviderListener listener) { - super.removeListener(listener); - fLabelProvider.removeListener(listener); - } - - public void addListener(ILabelProviderListener listener) { - super.addListener(listener); - fLabelProvider.addListener(listener); - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java deleted file mode 100644 index 255726504cc..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.StringTokenizer; - -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Widget; - -import org.eclipse.ui.IEditorRegistry; - -import org.eclipse.search.internal.ui.SearchMessages; - -public class FileTypeEditor extends SelectionAdapter implements DisposeListener, SelectionListener { - - private Combo fTextField; - private Button fBrowseButton; - private IEditorRegistry fResourceEditorRegistry; - - final static String TYPE_DELIMITER= SearchMessages.getString("FileTypeEditor.typeDelimiter"); //$NON-NLS-1$ - - public FileTypeEditor(IEditorRegistry registry, Combo textField, Button browseButton) { - fResourceEditorRegistry= registry; - fTextField= textField; - fBrowseButton= browseButton; - - fTextField.addDisposeListener(this); - fBrowseButton.addDisposeListener(this); - fBrowseButton.addSelectionListener(this); - } - - public void widgetDisposed(DisposeEvent event) { - Widget widget= event.widget; - if (widget == fTextField) - fTextField= null; - else if (widget == fBrowseButton) - fBrowseButton= null; - } - - public void widgetSelected(SelectionEvent event) { - if (event.widget == fBrowseButton) - handleBrowseButton(); - } - - public void widgetDoubleSelected(SelectionEvent event) { - } - /** - * Answer a collection of the currently-specified resource types - * - * @return java.util.Vector - */ - public Set getFileTypes() { - Set result= new HashSet(); - StringTokenizer tokenizer= new StringTokenizer(fTextField.getText(), TYPE_DELIMITER); - - while (tokenizer.hasMoreTokens()) { - String currentExtension= tokenizer.nextToken().trim(); - result.add(currentExtension); - } - return result; - } - /** - * Populate self's import types field based upon the passed types collection - * - * @param types java.util.Vector - */ - public void setFileTypes(Set types) { - fTextField.setText(typesToString(types)); - } - protected void handleBrowseButton() { - TypeFilteringDialog dialog= new TypeFilteringDialog(fTextField.getShell(), getFileTypes()); - if (dialog.open() == dialog.OK) { - setFileTypes(new HashSet(Arrays.asList(dialog.getResult()))); - } - } - - public static String typesToString(Set types) { - StringBuffer result= new StringBuffer(); - Iterator typesIter= types.iterator(); - boolean first= true; - while (typesIter.hasNext()) { - if (!first) { - result.append(TYPE_DELIMITER); - result.append(" "); //$NON-NLS-1$ - } else - first= false; - result.append(typesIter.next()); - } - return result.toString(); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java deleted file mode 100644 index 34a76dc7cef..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListContentProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.util.List; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * A specialized content provider to show a list of editor parts. - */ -public class ListContentProvider implements IStructuredContentProvider { - List fContents; - - public ListContentProvider() { - } - - public Object[] getElements(Object input) { - if (fContents != null && fContents == input) - return fContents.toArray(); - return new Object[0]; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (newInput instanceof List) - fContents= (List)newInput; - else - fContents= null; - // we use a fixed set. - } - - public void dispose() { - } - - public boolean isDeleted(Object o) { - return fContents != null && !fContents.contains(o); - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListDialog.java deleted file mode 100644 index 5004d260130..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ListDialog.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; - -import org.eclipse.ui.dialogs.SelectionDialog; - -/** - * Dialog that shows a list of items with icon and label. - */ -public class ListDialog extends SelectionDialog { - - private static final int WIDTH_IN_CHARACTERS= 55; - - private IStructuredContentProvider fContentProvider; - private ILabelProvider fLabelProvider; - private Object fInput; - private TableViewer fViewer; - private boolean fCreateCancelButton= true; - - public ListDialog(Shell parent, Object input, String title, String message, IStructuredContentProvider sp, ILabelProvider lp) { - super(parent); - setTitle(title); - setMessage(message); - fInput= input; - fContentProvider= sp; - fLabelProvider= lp; - } - - public void setCreateCancelButton(boolean value) { - fCreateCancelButton= value; - } - - /* - * Overrides method from Dialog - */ - protected Label createMessageArea(Composite composite) { - Label label = new Label(composite,SWT.WRAP); - label.setText(getMessage()); - GridData gd= new GridData(GridData.FILL_BOTH); - gd.widthHint= convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS); - label.setLayoutData(gd); - return label; - } - - /* - * Overrides method from Dialog - */ - protected Control createDialogArea(Composite container) { - Composite parent= (Composite) super.createDialogArea(container); - createMessageArea(parent); - fViewer= new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - fViewer.setContentProvider(fContentProvider); - - final Table table= fViewer.getTable(); - table.addMouseListener(new MouseAdapter() { - public void mouseDoubleClick(MouseEvent e) { - if (fCreateCancelButton) - okPressed(); - } - }); - fViewer.setLabelProvider(fLabelProvider); - fViewer.setInput(fInput); - List initialSelection= getInitialElementSelections(); - if (initialSelection != null) - fViewer.setSelection(new StructuredSelection(initialSelection)); - GridData gd= new GridData(GridData.FILL_BOTH); - gd.heightHint= convertHeightInCharsToPixels(15); - gd.widthHint= convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS); - table.setLayoutData(gd); - return table; - } - - /* - * Overrides method from Dialog - */ - protected void createButtonsForButtonBar(Composite parent) { - if (! fCreateCancelButton) - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); - else - super.createButtonsForButtonBar(parent); - } - - /* - * Overrides method from Dialog - */ - protected void okPressed() { - // Build a list of selected children. - ISelection selection= fViewer.getSelection(); - if (selection instanceof IStructuredSelection) - setResult(((IStructuredSelection)fViewer.getSelection()).toList()); - super.okPressed(); - } -} - - diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/MessageLine.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/MessageLine.java deleted file mode 100644 index 1b5cb3ca21a..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/MessageLine.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; - -/** - * A message line. It distinguishs between "normal" messages and errors. - * Setting an error message hides a currently displayed message until - * <code>clearErrorMessage</code> is called. - */ -public class MessageLine extends CLabel { - - private String fMessageText; - private String fErrorText; - - private Color fDefaultColor; - private RGB fErrorRGB; - private Color fErrorColor; - - private static RGB fgErrorRGB= new RGB(200, 0, 0); - - /** - * Creates a new message line as a child of the given parent. - * Error message will be shown with in the rgb color 200,0,0. - */ - public MessageLine(Composite parent) { - this(parent, SWT.LEFT); - } - - /** - * Creates a new message line as a child of the parent and with the given SWT stylebits. - * Error message will be shown with in the rgb color 200,0,0. - */ - public MessageLine(Composite parent, int style) { - super(parent, style); - fDefaultColor= getForeground(); - fErrorRGB= fgErrorRGB; - } - - /** - * Creates a new message line as a child of the parent and with the given SWT stylebits. - * Error message will be shown with in the given rgb color. - */ - public MessageLine(Composite parent, int style, RGB errorRGB) { - super(parent, style); - fDefaultColor= getForeground(); - fErrorRGB= errorRGB; - } - - /** - * Clears the currently displayed error message and redisplayes - * the message which was active before the error message was set. - */ - public void clearErrorMessage() { - setErrorMessage(null); - } - - /** - * Clears the currently displayed message. - */ - public void clearMessage() { - setMessage(null); - } - - /** - * Get the currently displayed error text. - * @return The error message. If no error message is displayed <code>null</code> is returned. - */ - public String getErrorMessage() { - return fErrorText; - } - - /** - * Get the currently displayed message. - * @return The message. If no message is displayed <code>null</code> is returned. - */ - public String getMessage() { - return fMessageText; - } - - /** - * Sets the default error color used by all message lines. - * Note: a call to this method only affects newly created MessageLines not existing ones. - */ - public static void setDefaultErrorColor(RGB color) { - fgErrorRGB= color; - } - - /** - * Display the given error message. A currently displayed message - * is saved and will be redisplayed when the error message is cleared. - */ - public void setErrorMessage(String message) { - fErrorText= message; - - if (message == null) { - setMessage(fMessageText); - } else { - if (fErrorColor == null) { - fErrorColor= new Color(getDisplay(), fErrorRGB); - addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - getErrorColor().dispose(); - } - }); - } - setForeground(fErrorColor); - setText(message); - } - } - - /** - * Set the message text. If the message line currently displays an error, - * the message is stored and will be shown after a call to clearErrorMessage - */ - public void setMessage(String message) { - fMessageText= message; - if (message == null) - message= ""; //$NON-NLS-1$ - if (fErrorText == null) { - setForeground(fDefaultColor); - setText(message); - } - } - - protected Color getErrorColor() { - return fErrorColor; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/RowLayouter.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/RowLayouter.java deleted file mode 100644 index 200b0b815ee..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/RowLayouter.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Control; - -import org.eclipse.jface.util.Assert; - -public class RowLayouter { - - public int spanHorizontalAlignment= -1; - public int spanGrabExcessHorizontalSpace= -1; - public int spanHorizontalSpan= -1; - public int spanHorizontalIndent= -1; - public int spanWidthHint= -1; - - public int spanVerticalAlignment= -1; - public int spanGrabExcessVerticalSpace= -1; - public int spanVerticalSpan= -1; - public int spanHeightHint= -1; - - private int fNumColumns; - private boolean fOrder; - private Control fLastControl; - private GridData[] fDefaultGridDatas= new GridData[4]; - - public RowLayouter(int numColumns) { - this(numColumns, false); - } - - public RowLayouter(int numColumns, boolean order) { - fNumColumns= numColumns; - fOrder= order; - } - - public void setDefaultSpan() { - spanHorizontalAlignment= GridData.FILL; - spanGrabExcessHorizontalSpace= 1; - } - - public void perform(Control c1) { - perform(new Control[] {c1}, 0); - } - - public void perform(Control c1, Control c2, int span) { - perform(new Control[] {c1, c2}, span); - } - - public void perform(Control c1, Control c2, Control c3, int span) { - perform(new Control[] {c1, c2, c3}, span); - } - - public void perform(Control[] controls, int spanColumn) { - int numColumns= numColumns(); - Assert.isTrue(controls.length <= numColumns); - order(controls); - int gridIndex= 0; - for (int i= 0; i < controls.length; i++) { - Control control= controls[i]; - GridData gd= (GridData)control.getLayoutData(); - if (gd == null) - gd= getGridData(gridIndex); - - if (i == spanColumn) { - int span= numColumns - (controls.length - 1); - gridIndex+= span; - if (gd == null) - gd= new GridData(); - applyDelta(gd); - gd.horizontalSpan= span; - } else { - gridIndex++; - } - control.setLayoutData(gd); - } - } - - private void applyDelta(GridData gd) { - if (spanHorizontalAlignment != -1) - gd.horizontalAlignment= spanHorizontalAlignment; - - if (spanGrabExcessHorizontalSpace != -1) { - if (spanGrabExcessHorizontalSpace == 0) - gd.grabExcessHorizontalSpace= false; - else - gd.grabExcessHorizontalSpace= true; - } - - - if (spanHorizontalSpan != -1) - gd.horizontalSpan= spanHorizontalSpan; - - if (spanHorizontalIndent != -1) - gd.horizontalIndent= spanHorizontalIndent; - - if (spanWidthHint != -1) - gd.widthHint= spanWidthHint; - - if (spanVerticalAlignment != -1) - gd.verticalAlignment= spanVerticalAlignment; - - if (spanGrabExcessVerticalSpace != -1) { - if (spanGrabExcessVerticalSpace == 0) - gd.grabExcessVerticalSpace= false; - else - gd.grabExcessVerticalSpace= true; - } - - if (spanVerticalSpan != -1) - gd.verticalSpan= spanVerticalSpan; - - if (spanHeightHint != -1) - gd.heightHint= spanHeightHint; - } - public void setDefaultGridData(GridData gd, int index) { - if (index >= fDefaultGridDatas.length) { - GridData[] newDatas= new GridData[index + 4]; - System.arraycopy(fDefaultGridDatas, 0, newDatas, 0, fDefaultGridDatas.length); - fDefaultGridDatas= newDatas; - } - fDefaultGridDatas[index]= gd; - } - - public GridData getGridData(int index) { - if (index > fDefaultGridDatas.length) - return null; - - return cloneGridData(fDefaultGridDatas[index]); - } - - public int numColumns() { - return fNumColumns; - } - - protected void order(Control[] controls) { - if (!fOrder) - return; - - for (int i= 0; i < controls.length; i++) { - Control control= controls[i]; - control.moveBelow(fLastControl); - fLastControl= control; - } - } - - protected GridData cloneGridData(GridData gd) { - if (gd == null) - return null; - - GridData result= new GridData(); - result.horizontalAlignment= gd.horizontalAlignment; - result.grabExcessHorizontalSpace= gd.grabExcessHorizontalSpace; - result.horizontalSpan= gd.horizontalSpan; - result.horizontalIndent= gd.horizontalIndent; - result.widthHint= gd.widthHint; - - result.verticalAlignment= gd.verticalAlignment; - result.grabExcessVerticalSpace= gd.grabExcessVerticalSpace; - result.verticalSpan= gd.verticalSpan; - result.heightHint= gd.heightHint; - return result; - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/SWTUtil.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/SWTUtil.java deleted file mode 100644 index dec338e18a2..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/SWTUtil.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.DragSource; -import org.eclipse.swt.dnd.DropTarget; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Caret; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Widget; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.util.Assert; - -/** - * Utility class to simplify access to some SWT resources. - */ -public class SWTUtil { - - /** - * Returns the standard display to be used. The method first checks, if - * the thread calling this method has an associated disaply. If so, this - * display is returned. Otherwise the method returns the default display. - */ - public static Display getStandardDisplay() { - Display display; - display= Display.getCurrent(); - if (display == null) - display= Display.getDefault(); - return display; - } - - /** - * Returns the shell for the given widget. If the widget doesn't represent - * a SWT object that manage a shell, <code>null</code> is returned. - * - * @return the shell for the given widget - */ - public static Shell getShell(Widget widget) { - if (widget instanceof Control) - return ((Control)widget).getShell(); - if (widget instanceof Caret) - return ((Caret)widget).getParent().getShell(); - if (widget instanceof DragSource) - return ((DragSource)widget).getControl().getShell(); - if (widget instanceof DropTarget) - return ((DropTarget)widget).getControl().getShell(); - if (widget instanceof Menu) - return ((Menu)widget).getParent().getShell(); - if (widget instanceof ScrollBar) - return ((ScrollBar)widget).getParent().getShell(); - - return null; - } - - private static double fgHorizontalDialogUnitSize= 0.0; - private static double fgVerticalDialogUnitSize= 0.0; - - private static void initializeDialogUnits(Control control) { - GC gc= new GC(control); - gc.setFont(control.getFont()); - int averageWidth= gc.getFontMetrics().getAverageCharWidth(); - int height = gc.getFontMetrics().getHeight(); - gc.dispose(); - - fgHorizontalDialogUnitSize = averageWidth * 0.25; - fgVerticalDialogUnitSize = height * 0.125; - } - - /** - * @see DialogPage#convertHeightInCharsToPixels - */ - private static int convertHeightInCharsToPixels(int chars) { - return convertVerticalDLUsToPixels(chars * 8); - } - - /** - * @see DialogPage#convertHorizontalDLUsToPixels - */ - private static int convertHorizontalDLUsToPixels(int dlus) { - return (int)Math.round(dlus * fgHorizontalDialogUnitSize); - } - - /** - * @see DialogPage#convertVerticalDLUsToPixels - */ - private static int convertVerticalDLUsToPixels(int dlus) { - return (int)Math.round(dlus * fgVerticalDialogUnitSize); - } - - /** - * @see DialogPage#convertWidthInCharsToPixels - */ - private static int convertWidthInCharsToPixels(int chars) { - return convertHorizontalDLUsToPixels(chars * 4); - } - - /** - * @see DialogPage#convertWidthInCharsToPixels - */ - public static int convertWidthInCharsToPixels(int chars, Text text) { - if (fgHorizontalDialogUnitSize == 0.0) - initializeDialogUnits(text); - return convertHorizontalDLUsToPixels(chars * 4); - } - - /** - * Returns a width hint for a button control. - */ - public static int getButtonWidthHint(Button button) { - if (fgHorizontalDialogUnitSize == 0.0) { - initializeDialogUnits(button); - } - int widthHint= convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); - return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); - } - - /** - * Returns a height hint for a button control. - */ - public static int getButtonHeigthHint(Button button) { - if (fgHorizontalDialogUnitSize == 0.0) { - initializeDialogUnits(button); - } - return convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); - } - - /** - * Sets width and height hint for the button control. - * <b>Note:</b> This is a NOP if the button's layout data is not - * an instance of <code>GridData</code>. - * - * @param the button for which to set the dimension hint - */ - public static void setButtonDimensionHint(Button button) { - Assert.isNotNull(button); - Object gd= button.getLayoutData(); - if (gd instanceof GridData) { - ((GridData)gd).heightHint= SWTUtil.getButtonHeigthHint(button); - ((GridData)gd).widthHint= SWTUtil.getButtonWidthHint(button); - } - } -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/StringMatcher.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/StringMatcher.java deleted file mode 100644 index f15d95168e4..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/StringMatcher.java +++ /dev/null @@ -1,384 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.util.*; - -/** - * A string pattern matcher, suppporting * and ? wildcards. - */ -public class StringMatcher { - protected String fPattern; - protected int fLength; // pattern length - protected boolean fIgnoreWildCards; - protected boolean fIgnoreCase; - protected boolean fHasLeadingStar; - protected boolean fHasTrailingStar; - protected String fSegments[]; //the given pattern is split into * separated segments - - /* boundary value beyond which we don't need to search in the text */ - protected int fBound= 0; - - - protected static final char fSingleWildCard= '\u0000'; - - public static class Position { - int start; //inclusive - int end; //exclusive - public Position(int start, int end) { - this.start= start; - this.end= end; - } - public int getStart() { - return start; - } - public int getEnd() { - return end; - } - } - /** - * StringMatcher constructor takes in a String object that is a simple - * pattern which may contain ‘*’ for 0 and many characters and - * ‘?’ for exactly one character. - * - * Literal '*' and '?' characters must be escaped in the pattern - * e.g., "\*" means literal "*", etc. - * - * Escaping any other character (including the escape character itself), - * just results in that character in the pattern. - * e.g., "\a" means "a" and "\\" means "\" - * - * If invoking the StringMatcher with string literals in Java, don't forget - * escape characters are represented by "\\". - * - * @param pattern the pattern to match text against - * @param ignoreCase if true, case is ignored - * @param ignoreWildCards if true, wild cards and their escape sequences are ignored - * (everything is taken literally). - */ - public StringMatcher(String pattern, boolean ignoreCase, boolean ignoreWildCards) { - if (pattern == null) - throw new IllegalArgumentException(); - fIgnoreCase= ignoreCase; - fIgnoreWildCards= ignoreWildCards; - fPattern= pattern; - fLength= pattern.length(); - - if (fIgnoreWildCards) { - parseNoWildCards(); - } else { - parseWildCards(); - } - } - /** - * Find the first occurrence of the pattern between <code>start</code)(inclusive) - * and <code>end</code>(exclusive). - * @param <code>text</code>, the String object to search in - * @param <code>start</code>, the starting index of the search range, inclusive - * @param <code>end</code>, the ending index of the search range, exclusive - * @return an <code>StringMatcher.Position</code> object that keeps the starting - * (inclusive) and ending positions (exclusive) of the first occurrence of the - * pattern in the specified range of the text; return null if not found or subtext - * is empty (start==end). A pair of zeros is returned if pattern is empty string - * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc" - * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned - */ - public StringMatcher.Position find(String text, int start, int end) { - if (text == null) - throw new IllegalArgumentException(); - - int tlen= text.length(); - if (start < 0) - start= 0; - if (end > tlen) - end= tlen; - if (end < 0 ||start >= end ) - return null; - if (fLength == 0) - return new Position(start, start); - if (fIgnoreWildCards) { - int x= posIn(text, start, end); - if (x < 0) - return null; - return new Position(x, x+fLength); - } - - int segCount= fSegments.length; - if (segCount == 0)//pattern contains only '*'(s) - return new Position (start, end); - - int curPos= start; - int matchStart= -1; - int i; - for (i= 0; i < segCount && curPos < end; ++i) { - String current= fSegments[i]; - int nextMatch= regExpPosIn(text, curPos, end, current); - if (nextMatch < 0 ) - return null; - if(i == 0) - matchStart= nextMatch; - curPos= nextMatch + current.length(); - } - if (i < segCount) - return null; - return new Position(matchStart, curPos); - } - /** - * match the given <code>text</code> with the pattern - * @return true if matched eitherwise false - * @param <code>text</code>, a String object - */ - public boolean match(String text) { - return match(text, 0, text.length()); - } - /** - * Given the starting (inclusive) and the ending (exclusive) positions in the - * <code>text</code>, determine if the given substring matches with aPattern - * @return true if the specified portion of the text matches the pattern - * @param String <code>text</code>, a String object that contains the substring to match - * @param int <code>start<code> marks the starting position (inclusive) of the substring - * @param int <code>end<code> marks the ending index (exclusive) of the substring - */ - public boolean match(String text, int start, int end) { - if (null == text) - throw new IllegalArgumentException(); - - if (start > end) - return false; - - if (fIgnoreWildCards) - return (end - start == fLength) && fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength); - int segCount= fSegments.length; - if (segCount == 0 && (fHasLeadingStar || fHasTrailingStar)) // pattern contains only '*'(s) - return true; - if (start == end) - return fLength == 0; - if (fLength == 0) - return start == end; - - int tlen= text.length(); - if (start < 0) - start= 0; - if (end > tlen) - end= tlen; - - int tCurPos= start; - int bound= end - fBound; - if ( bound < 0) - return false; - int i=0; - String current= fSegments[i]; - int segLength= current.length(); - - /* process first segment */ - if (!fHasLeadingStar){ - if(!regExpRegionMatches(text, start, current, 0, segLength)) { - return false; - } else { - ++i; - tCurPos= tCurPos + segLength; - } - } - - /* process middle segments */ - while (i < segCount) { - current= fSegments[i]; - int currentMatch; - int k= current.indexOf(fSingleWildCard); - if (k < 0) { - currentMatch= textPosIn(text, tCurPos, end, current); - if (currentMatch < 0) - return false; - } else { - currentMatch= regExpPosIn(text, tCurPos, end, current); - if (currentMatch < 0) - return false; - } - tCurPos= currentMatch + current.length(); - i++; - } - - /* process final segment */ - if (!fHasTrailingStar && tCurPos != end) { - int clen= current.length(); - return regExpRegionMatches(text, end - clen, current, 0, clen); - } - return i == segCount ; - } - /** - * This method parses the given pattern into segments seperated by wildcard '*' characters. - * Since wildcards are not being used in this case, the pattern consists of a single segment. - */ - private void parseNoWildCards() { - fSegments= new String[1]; - fSegments[0]= fPattern; - fBound= fLength; - } - /** - * Parses the given pattern into segments seperated by wildcard '*' characters. - * @param p, a String object that is a simple regular expression with ‘*’ and/or ‘?’ - */ - private void parseWildCards() { - if(fPattern.startsWith("*"))//$NON-NLS-1$ - fHasLeadingStar= true; - if(fPattern.endsWith("*")) {//$NON-NLS-1$ - /* make sure it's not an escaped wildcard */ - if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') { - fHasTrailingStar= true; - } - } - - Vector temp= new Vector(); - - int pos= 0; - StringBuffer buf= new StringBuffer(); - while (pos < fLength) { - char c= fPattern.charAt(pos++); - switch (c) { - case '\\': - if (pos >= fLength) { - buf.append(c); - } else { - char next= fPattern.charAt(pos++); - /* if it's an escape sequence */ - if (next == '*' || next == '?' || next == '\\') { - buf.append(next); - } else { - /* not an escape sequence, just insert literally */ - buf.append(c); - buf.append(next); - } - } - break; - case '*': - if (buf.length() > 0) { - /* new segment */ - temp.addElement(buf.toString()); - fBound += buf.length(); - buf.setLength(0); - } - break; - case '?': - /* append special character representing single match wildcard */ - buf.append(fSingleWildCard); - break; - default: - buf.append(c); - } - } - - /* add last buffer to segment list */ - if (buf.length() > 0) { - temp.addElement(buf.toString()); - fBound += buf.length(); - } - - fSegments= new String[temp.size()]; - temp.copyInto(fSegments); - } - /** - * @param <code>text</code>, a string which contains no wildcard - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int posIn(String text, int start, int end) {//no wild card in pattern - int max= end - fLength; - - if (!fIgnoreCase) { - int i= text.indexOf(fPattern, start); - if (i == -1 || i > max) - return -1; - return i; - } - - for (int i= start; i <= max; ++i) { - if (text.regionMatches(true, i, fPattern, 0, fLength)) - return i; - } - - return -1; - } - /** - * @param <code>text</code>, a simple regular expression that may only contain '?'(s) - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @param <code>p</code>, a simple regular expression that may contains '?' - * @param <code>caseIgnored</code>, wether the pattern is not casesensitive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int regExpPosIn(String text, int start, int end, String p) { - int plen= p.length(); - - int max= end - plen; - for (int i= start; i <= max; ++i) { - if (regExpRegionMatches(text, i, p, 0, plen)) - return i; - } - return -1; - } - /** - * - * @return boolean - * @param <code>text</code>, a String to match - * @param <code>start</code>, int that indicates the starting index of match, inclusive - * @param <code>end</code> int that indicates the ending index of match, exclusive - * @param <code>p</code>, String, String, a simple regular expression that may contain '?' - * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive - */ - protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) { - while (plen-- > 0) { - char tchar= text.charAt(tStart++); - char pchar= p.charAt(pStart++); - - /* process wild cards */ - if (!fIgnoreWildCards) { - /* skip single wild cards */ - if (pchar == fSingleWildCard) { - continue; - } - } - if (pchar == tchar) - continue; - if (fIgnoreCase) { - if (Character.toUpperCase(tchar) == Character.toUpperCase(pchar)) - continue; - // comparing after converting to upper case doesn't handle all cases; - // also compare after converting to lower case - if (Character.toLowerCase(tchar) == Character.toLowerCase(pchar)) - continue; - } - return false; - } - return true; - } - /** - * @param <code>text</code>, the string to match - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @param code>p</code>, a string that has no wildcard - * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int textPosIn(String text, int start, int end, String p) { - - int plen= p.length(); - int max= end - plen; - - if (!fIgnoreCase) { - int i= text.indexOf(p, start); - if (i == -1 || i > max) - return -1; - return i; - } - - for (int i= start; i <= max; ++i) { - if (text.regionMatches(true, i, p, 0, plen)) - return i; - } - - return -1; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/TypeFilteringDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/TypeFilteringDialog.java deleted file mode 100644 index ac0fa4eeef3..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/TypeFilteringDialog.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.internal.ui.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.viewers.CheckboxTableViewer; - -import org.eclipse.ui.IFileEditorMapping; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.FileEditorMappingContentProvider; -import org.eclipse.ui.dialogs.FileEditorMappingLabelProvider; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.help.WorkbenchHelp; - -import org.eclipse.search.internal.ui.ISearchHelpContextIds; -import org.eclipse.search.internal.ui.SearchMessages; - -/** - * The TypeFilteringDialog is a SelectionDialog that allows the user to select a file editor. - * XXX: Workbench should offer this dialog (public API), see: 1GIYHMY: ITPUI:WINNT - DCR: TypeFilteringDialog should be public API - */ -public class TypeFilteringDialog extends SelectionDialog { - private Button fAddTypesButton; - - private Collection fInitialSelections; - - // the visual selection widget group - private CheckboxTableViewer fListViewer; - - // sizing constants - private final static int SIZING_SELECTION_WIDGET_HEIGHT= 250; - private final static int SIZING_SELECTION_WIDGET_WIDTH= 300; - - private Text fUserDefinedText; - - private IFileEditorMapping[] fCurrentInput; - /** - * Creates a type selection dialog using the supplied entries. Set the initial selections to those - * whose extensions match the preselections. - */ - public TypeFilteringDialog(Shell parentShell, Collection preselections) { - super(parentShell); - setTitle(SearchMessages.getString("TypesFiltering.title")); //$NON-NLS-1$ - fInitialSelections= preselections; - setMessage(SearchMessages.getString("TypesFiltering.message")); //$NON-NLS-1$ - } - - /** - * Add the selection and deselection buttons to the dialog. - * @param composite org.eclipse.swt.widgets.Composite - */ - private void addSelectionButtons(Composite composite) { - - Composite buttonComposite= new Composite(composite, SWT.RIGHT); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - buttonComposite.setLayout(layout); - GridData data = - new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); - data.grabExcessHorizontalSpace= true; - composite.setData(data); - - Button selectButton = - createButton( - buttonComposite, - IDialogConstants.SELECT_ALL_ID, - SearchMessages.getString("TypesFiltering.selectAll"), //$NON-NLS-1$ - false); - - SelectionListener listener= new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - getListViewer().setAllChecked(true); - } - }; - selectButton.addSelectionListener(listener); - - Button deselectButton = - createButton( - buttonComposite, - IDialogConstants.DESELECT_ALL_ID, - SearchMessages.getString("TypesFiltering.deselectAll"), //$NON-NLS-1$ - false); - - listener= new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - getListViewer().setAllChecked(false); - - } - }; - deselectButton.addSelectionListener(listener); - - } - - /** - * Add the currently-specified extensions. - */ - private void addUserDefinedEntries(List result) { - - StringTokenizer tokenizer = - new StringTokenizer(fUserDefinedText.getText(), FileTypeEditor.TYPE_DELIMITER); - - //Allow the *. and . prefix and strip out the extension - while (tokenizer.hasMoreTokens()) { - String currentExtension= tokenizer.nextToken().trim(); - if (!currentExtension.equals("")) //$NON-NLS-1$ - result.add(currentExtension); - } - } - - /** - * Visually checks the previously-specified elements in this dialog's list - * viewer. - */ - private void checkInitialSelections() { - - IFileEditorMapping editorMappings[] = - PlatformUI.getWorkbench().getEditorRegistry().getFileEditorMappings(); - ArrayList selectedMappings= new ArrayList(); - - for (int i= 0; i < editorMappings.length; i++) { - IFileEditorMapping mapping= editorMappings[i]; - if (fInitialSelections.contains(mapping.getLabel())) { - fListViewer.setChecked(mapping, true); - selectedMappings.add(mapping.getLabel()); - } - } - - //Now add in the ones not selected to the user defined list - Iterator initialIterator= fInitialSelections.iterator(); - StringBuffer entries= new StringBuffer(); - boolean first= true; - while (initialIterator.hasNext()) { - String nextExtension= (String)initialIterator.next(); - if (!selectedMappings.contains(nextExtension)) { - if (!first) { - entries.append(FileTypeEditor.TYPE_DELIMITER); - entries.append(" "); //$NON-NLS-1$ - } - first= false; - entries.append(nextExtension); - } - } - fUserDefinedText.setText(entries.toString()); - } - - /* (non-Javadoc) - * Method declared in Window. - */ - protected void configureShell(Shell shell) { - super.configureShell(shell); - WorkbenchHelp.setHelp(shell, ISearchHelpContextIds.TYPE_FILTERING_DIALOG); - } - - /* (non-Javadoc) - * Method declared on Dialog. - */ - protected Control createDialogArea(Composite parent) { - // page group - Composite composite= (Composite)super.createDialogArea(parent); - - createMessageArea(composite); - - fListViewer= CheckboxTableViewer.newCheckList(composite, SWT.BORDER); - GridData data= new GridData(GridData.FILL_BOTH); - data.heightHint= SIZING_SELECTION_WIDGET_HEIGHT; - data.widthHint= SIZING_SELECTION_WIDGET_WIDTH; - fListViewer.getTable().setLayoutData(data); - - fListViewer.setLabelProvider(FileEditorMappingLabelProvider.INSTANCE); - fListViewer.setContentProvider(FileEditorMappingContentProvider.INSTANCE); - - addSelectionButtons(composite); - - createUserEntryGroup(composite); - - initializeViewer(); - - // initialize page - if (fInitialSelections != null && !fInitialSelections.isEmpty()) - checkInitialSelections(); - - return composite; - } - - /** - * Create the group that shows the user defined entries for the dialog. - * @param parent the parent this is being created in. - */ - private void createUserEntryGroup(Composite parent) { - - // destination specification group - Composite userDefinedGroup= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - userDefinedGroup.setLayout(layout); - userDefinedGroup.setLayoutData( - new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); - - new Label(userDefinedGroup, SWT.NONE).setText( - SearchMessages.getString("TypesFiltering.otherExtensions")); //$NON-NLS-1$ - - // user defined entry field - fUserDefinedText= new Text(userDefinedGroup, SWT.SINGLE | SWT.BORDER); - GridData data = - new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); - fUserDefinedText.setLayoutData(data); - } - - /** - * Return the input to the dialog. - */ - private IFileEditorMapping[] getInput() { - - //Filter the mappings to be just those with a wildcard extension - if (fCurrentInput == null) { - List wildcardEditors= new ArrayList(); - IFileEditorMapping[] allMappings = - PlatformUI.getWorkbench().getEditorRegistry().getFileEditorMappings(); - for (int i= 0; i < allMappings.length; i++) { - if (allMappings[i].getName().equals("*")) //$NON-NLS-1$ - wildcardEditors.add(allMappings[i]); - } - fCurrentInput= new IFileEditorMapping[wildcardEditors.size()]; - wildcardEditors.toArray(fCurrentInput); - } - - return fCurrentInput; - } - - /** - * Initializes this dialog's viewer after it has been laid out. - */ - private void initializeViewer() { - fListViewer.setInput(getInput()); - } - - /** - * The <code>ListSelectionDialog</code> implementation of this - * <code>Dialog</code> method builds a list of the selected elements for later - * retrieval by the client and closes this dialog. - */ - protected void okPressed() { - - // Get the input children. - IFileEditorMapping[] children= getInput(); - - List list= new ArrayList(); - - // Build a list of selected children. - for (int i= 0; i < children.length; ++i) { - IFileEditorMapping element= children[i]; - if (fListViewer.getChecked(element)) - list.add(element.getLabel()); - } - - addUserDefinedEntries(list); - setResult(list); - super.okPressed(); - } - - protected CheckboxTableViewer getListViewer() { - return fListViewer; - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/ui/IActionGroupFactory.java b/org.eclipse.search/search/org/eclipse/search/ui/IActionGroupFactory.java deleted file mode 100644 index 5fb18a92e4d..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/IActionGroupFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2000, 2002 IBM Corp. and others.. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Corporation - initial API and implementation - */ -package org.eclipse.search.ui; - -import org.eclipse.ui.actions.ActionGroup; - -/** - * Allows to specify an <code>ActionGroup</code> factory - * which will be used by the Search view to create an - * <code>ActionGroup</code> which is used to build the - * actions bars and the context menu. - * <p> - * Note: Local tool bar contributions are not supported in 2.0. - * </p> - * - * Clients can implement this interface and pass an - * instance to the search result view. - * - * @see org.eclipse.ui.actions.ActionGroup - * @see ISearchResultView#searchStarted - * @since 2.0 - */ -public interface IActionGroupFactory { - - /** - * Creates an <code>ActionGroup</code> for a Search view. - * - * @param searchView the search result view for which the group is made - * @see org.eclipse.ui.actions.ActionGroup - */ - ActionGroup createActionGroup(ISearchResultView searchView); -} diff --git a/org.eclipse.search/search/org/eclipse/search/ui/IContextMenuConstants.java b/org.eclipse.search/search/org/eclipse/search/ui/IContextMenuConstants.java deleted file mode 100644 index c4885f467d4..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/IContextMenuConstants.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.ui.IWorkbenchActionConstants; - -/** - * Constants for menu groups used in context menus for Search views and editors. - * <p> - * This interface declares constants only; it is not intended to be implemented. - * </p> - * - * @since 2.0 - */ -public interface IContextMenuConstants { - - /** - * Pop-up menu: name of group for goto actions (value <code>"group.open"</code>). - * <p> - * Examples for open actions are: - * <ul> - * <li>Go Into</li> - * <li>Go To</li> - * </ul> - * </p> - */ - public static final String GROUP_GOTO= "group.goto"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for open actions (value <code>"group.open"</code>). - * <p> - * Examples for open actions are: - * <ul> - * <li>Open To</li> - * <li>Open With</li> - * </ul> - * </p> - */ - public static final String GROUP_OPEN= "group.open"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for show actions (value <code>"group.show"</code>). - * <p> - * Examples for show actions are: - * <ul> - * <li>Show in Navigator</li> - * <li>Show in Type Hierarchy</li> - * </ul> - * </p> - */ - public static final String GROUP_SHOW= "group.show"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for new actions (value <code>"group.new"</code>). - * <p> - * Examples for new actions are: - * <ul> - * <li>Create new class</li> - * <li>Create new interface</li> - * </ul> - * </p> - */ - public static final String GROUP_NEW= "group.new"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for build actions (value <code>"group.build"</code>). - */ - public static final String GROUP_BUILD= "group.build"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for reorganize actions (value <code>"group.reorganize"</code>). - */ - public static final String GROUP_REORGANIZE= IWorkbenchActionConstants.GROUP_REORGANIZE; - - /** - * Pop-up menu: name of group for code generation or refactoring actions ( - * value <code>"group.generate"</code>). - */ - public static final String GROUP_GENERATE= "group.generate"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for search actions (value <code>"group.search"</code>). - */ - public static final String GROUP_SEARCH= "group.search"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for additional actions (value <code>"group.additions"</code>). - */ - public static final String GROUP_ADDITIONS= "additions"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for viewer setup actions (value <code>"group.viewerSetup"</code>). - */ - public static final String GROUP_VIEWER_SETUP= "group.viewerSetup"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for properties actions (value <code>"group.properties"</code>). - */ - public static final String GROUP_PROPERTIES= "group.properties"; //$NON-NLS-1$ - - /** - * Pop-up menu: name of group for remove match actions (value <code>"group.removeMatches"</code>). - */ - public static final String GROUP_REMOVE_MATCHES= "group.removeMatches"; //$NON-NLS-1$ -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/ui/IContextMenuContributor.java b/org.eclipse.search/search/org/eclipse/search/ui/IContextMenuContributor.java deleted file mode 100644 index 618069ec72d..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/IContextMenuContributor.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.viewers.IInputSelectionProvider; - -/** - * Specify how clients can add menu items - * to the context menu of the search result view. - * A class that contributes context menu items - * must implement this interface and pass an - * instance of itself to the search result view. - * - * @see ISearchResultView#searchStarted - */ -public interface IContextMenuContributor { - - /** - * Contributes menu items to the given context menu appropriate for the - * given selection. - * - * @param menu the menu to which the items are added - * @param inputProvider the selection and input provider - */ - public void fill(IMenuManager menu, IInputSelectionProvider inputProvider); -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/ui/IGroupByKeyComputer.java b/org.eclipse.search/search/org/eclipse/search/ui/IGroupByKeyComputer.java deleted file mode 100644 index 1d1a464de5c..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/IGroupByKeyComputer.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.core.resources.IMarker; - -/** - * Computes the key by which the markers in the search result view - * are grouped. - */ -public interface IGroupByKeyComputer { - - /** - * Computes and returns key by which the given marker is grouped. - * - * @param marker the marker for which the key must be computed - * @return an object that will be used as the key for that marker, - * <code>null</code> if the marker seems to be invalid - */ - public Object computeGroupByKey(IMarker marker); -} diff --git a/org.eclipse.search/search/org/eclipse/search/ui/ISearchPage.java b/org.eclipse.search/search/org/eclipse/search/ui/ISearchPage.java deleted file mode 100644 index 9e124e5cf18..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/ISearchPage.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.jface.dialogs.IDialogPage; - -/** - * Defines a page inside the search dialog. - * Clients can contribute their own search page to the - * dialog by implementing this interface, typically as a subclass - * of <code>DialogPage</code>. - * <p> - * The search dialog calls the <code>performAction</code> method when the Search - * button is pressed. - * <p> - * - * @see org.eclipse.jface.dialogs.IDialogPage - * @see org.eclipse.jface.dialogs.DialogPage - */ -public interface ISearchPage extends IDialogPage { - - /** - * Performs the action for this page. - * The search dialog calls this method when the Search - * button is pressed. - * - * @return <code>true</code> if the dialog can be closed after execution - */ - public boolean performAction(); - - /** - * Sets the container of this page. - * The search dialog calls this method to initialize this page. - * Implementations may store the reference to the container. - * - * @param container the container for this page - */ - public void setContainer(ISearchPageContainer container); -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/ui/ISearchPageContainer.java b/org.eclipse.search/search/org/eclipse/search/ui/ISearchPageContainer.java deleted file mode 100644 index 1830402b966..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/ISearchPageContainer.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.jface.operation.IRunnableContext; -import org.eclipse.jface.viewers.ISelection; - -import org.eclipse.ui.IWorkingSet; - -/** - * Offers client access to the search dialog. - * A search page can enable or disable the dialog's action - * button and get an operation context to perform the action. - * The dialog itself cannot be accessed directly. - * <p> - * This interface is not intended to be implemented by clients. - * </p> - */ -public interface ISearchPageContainer { - - /** - * Workspace scope (value <code>0</code>). - * - * @since 2.0 - */ - public static final int WORKSPACE_SCOPE= 0; - - /** - * Selection scope (value <code>1</code>). - * - * @since 2.0 - */ - public static final int SELECTION_SCOPE= 1; - - /** - * Working set scope (value <code>2</code>). - * - * @since 2.0 - */ - public static final int WORKING_SET_SCOPE= 2; - - /** - * Returns the selection with which this container was opened. - * - * @return the selection passed to this container when it was opened - */ - public ISelection getSelection(); - - /** - * Returns the context for the search operation. - * This context allows progress to be shown inside the search dialog. - * - * @return the <code>IRunnableContext</code> for the search operation - */ - public IRunnableContext getRunnableContext(); - - /** - * Sets the enable state of the perform action button - * of this container. - * - * @param state <code>true</code> to enable the button which performs the action - */ - public void setPerformActionEnabled(boolean state); - - - /** - * Returns search container's selected scope. - * The scope is WORKSPACE_SCOPE, SELECTION_SCOPE or WORKING_SET_SCOPE. - * - * @return the selected scope - * @since 2.0 - */ - public int getSelectedScope(); - - /** - * Sets the selected scope of this search page container. - * The scope is WORKSPACE_SCOPE, SELECTION_SCOPE or WORKING_SET_SCOPE. - * - * @return the selected scope - * @since 2.0 - */ - public void setSelectedScope(int scope); - - /** - * Tells whether a valid scope is selected. - * - * @return a <code>true</code> if a valid scope is selected in this search page container - * @since 2.0 - */ - public boolean hasValidScope(); - - /** - * Returns the selected working sets of this container. - * - * @return an array with the selected working sets or <code>null</code> if the scope is not WORKING_SET_SCOPE - * @since 2.0 - */ - public IWorkingSet[] getSelectedWorkingSets(); - - /** - * Sets the selected working sets of this container. - * - * @param workingSets an array of IWorkingSet - * @since 2.0 - */ - public void setSelectedWorkingSets(IWorkingSet[] workingSets); -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/ui/ISearchPageScoreComputer.java b/org.eclipse.search/search/org/eclipse/search/ui/ISearchPageScoreComputer.java deleted file mode 100644 index 24faeeb2ad0..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/ISearchPageScoreComputer.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -/** - * Computes a score that is used by the search dialog - * to find the best fitting page for a selection when opened. - * The score has no upper limit but must be at least - * <code>LOWEST</code>. Higher values means the page is better - * suited for the given selection input. - * <p> - * For example, a Java-specific search page score computer could test - * if the page is a Java search page and returns high scores - * for Java elements as selection input. - * </p> - */ -public interface ISearchPageScoreComputer { - - /** - * Invalid score value indicating a score is unknown or undecided. - */ - public static final int UNKNOWN= -1; - - /** - * Lowest possible valid score. - */ - public static final int LOWEST= 0; - - /** - * Computes and returns a score indicating how good the page with the given - * id can handle the given input element. - * The search page id appears as the <code>id</code> attribute of the - * <code><page></code> element contributed to the - * search pages extension point (<code>"org.eclipse.search.searchPages"</code>). - * - * @param pageId the string id of the page for which the score is computed - * @param input the object based on which the page should open - * @return a score higher or equal to <code>LOWEST</code>, or - * <code>UNKNOWN</code> if this computer cannot decide - */ - public int computeScore(String pageId, Object input); -} diff --git a/org.eclipse.search/search/org/eclipse/search/ui/ISearchResultView.java b/org.eclipse.search/search/org/eclipse/search/ui/ISearchResultView.java deleted file mode 100644 index 5625348efa9..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/ISearchResultView.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2002. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.ui.IViewPart; - -/** - * Provides client access to the search result view. - * Each element in the view is a <code>ISearchResultViewEntry</code>, - * which groups markers based on the <code>groupByKey</code> provided - * by the client each time when adding a match. If every match should - * show up in the search result view then the match itself can be used - * as key. - * <p> - * The search result view has id <code>"org.eclipse.search.SearchResultView"</code>. - * </p> - * <p> - * This interface is not intended to be implemented by clients. - * </p> - */ -public interface ISearchResultView extends IViewPart { - - /** - * Informs the view that a search has started. - * Provides all necessary information to create an entry in the search result - * view. - * If every match should show up in the search result view then the match - * itself can be used as key. - * - * @param groupFactory the action group factory - * or <code>null</code> if no factory is provided. - * @param singularLabel the label to be used for this search occurrence - * if there is one match - * or <code>null</code> if the pluralLabelPattern should be used - * @param pluralLabelPattern the label pattern to be used for this search occurrence - * if there are more than one matches or none. - * This string may contain {0} which will be replace by the match count - * @param imageDescriptor the image descriptor to be used for this search occurrence, - * or <code>null</code> if this search should not have an image - * @param pageId the id of the search page which started the search - * @param labelProvider the label provider used by this search result view - * or <code>null</code> if the default provider should be used. - * The default label provider shows the resource name and the corresponding image. - * @param gotoAction the action used by the view to go to a marker - * @param groupByKeyComputer the computer used by the view to compute the key for a marker - * @param operation the runnable used by the view to repeat the search - * - * @see IActionGroupFactory - * @since 2.0 - */ - public void searchStarted( - IActionGroupFactory groupFactory, - String singularLabel, - String pluralLabelPattern, - ImageDescriptor imageDescriptor, - String pageId, - ILabelProvider labelProvider, - IAction gotoAction, - IGroupByKeyComputer groupByKeyComputer, - IRunnableWithProgress operation); - - /** - * Returns the current selection of the search result view - * - * @return the current selection of the search result view - * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection - */ - public ISelection getSelection(); - - /** - * Informs the view that a search has started. - * Provides all necessary information to create an entry in the search result - * view. - * If every match should show up in the search result view then the match - * itself can be used as key. - * - * @param pageId the id of the search page which started the search - * @param label the label to be used for this search occurrence - * @param imageDescriptor the image descriptor to be used for this search occurrence, - * or <code>null</code> if this search should not have an image - * @param contributor the context menu contributor - * or <code>null</code> if no context menu is contributed - * @param labelProvider the label provider used by this search result view - * or <code>null</code> if the default provider should be used. - * The default label provider shows the resource name and the corresponding image. - * @param gotoAction the action used by the view to go to a marker - * @param groupByKeyComputer the computer used by the view to compute the key for a marker - * @param operation the runnable used by the view to repeat the search - * @deprecated As of build > 20011107, replaced by the new version with additonal parameter - */ - public void searchStarted( - String pageId, - String label, - ImageDescriptor imageDescriptor, - IContextMenuContributor contributor, - ILabelProvider labelProvider, - IAction gotoAction, - IGroupByKeyComputer groupByKeyComputer, - IRunnableWithProgress operation); - - /** - * Informs the view that a search has started. - * Provides all necessary information to create an entry in the search result - * view. - * If every match should show up in the search result view then the match - * itself can be used as key. - * - * @param pageId the id of the search page which started the search - * @param singularLabel the label to be used for this search occurrence - * if there is one match - * or <code>null</code> if the pluralLabelPattern should be used - * @param pluralLabelPattern the label pattern to be used for this search occurrence - * if there are more than one matches or none. - * This string may contain {0} which will be replace by the match count - * @param imageDescriptor the image descriptor to be used for this search occurrence, - * or <code>null</code> if this search should not have an image - * @param contributor the context menu contributor - * or <code>null</code> if no context menu is contributed - * @param labelProvider the label provider used by this search result view - * or <code>null</code> if the default provider should be used. - * The default label provider shows the resource name and the corresponding image. - * @param gotoAction the action used by the view to go to a marker - * @param groupByKeyComputer the computer used by the view to compute the key for a marker - * @param operation the runnable used by the view to repeat the search - * @since 2.0 - * @deprecated As of build > 20020514, replaced by the new version which provides an action group factory - */ - public void searchStarted( - String pageId, - String singularLabel, - String pluralLabelPattern, - ImageDescriptor imageDescriptor, - IContextMenuContributor contributor, - ILabelProvider labelProvider, - IAction gotoAction, - IGroupByKeyComputer groupByKeyComputer, - IRunnableWithProgress operation); - - /** - * Informs the view that the search has finished. - * This method must also be called in case of the search - * fails or has been canceled. - */ - public void searchFinished(); - - /** - * Informs the view that a match has been found. - * Provides all necessary information to create a search result entry in this - * view. - * <p> - * Note: It is the clients responsibility to create the marker for this match. - * </p> - * - * @param description the text description of the match - * @param groupByKey the <code>Object</code> by which this match is grouped - * @param marker the marker for this match - * @param resource the marker's resource passed for optimization - */ - public void addMatch(String description, Object groupByKey, IResource resource, IMarker marker); - - /** - * Returns the label provider of a search result view. - * - * @return the label provider of a search result view or <code>null</code> - * @since 2.0 - */ - public ILabelProvider getLabelProvider(); -}
\ No newline at end of file diff --git a/org.eclipse.search/search/org/eclipse/search/ui/ISearchResultViewEntry.java b/org.eclipse.search/search/org/eclipse/search/ui/ISearchResultViewEntry.java deleted file mode 100644 index 81d6f325450..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/ISearchResultViewEntry.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; - -/** - * Specifies a search result view entry. - * This entry provides information about the markers - * it groups by a client defined key. Each entry in the search - * result view corresponds to a different key. - * <p> - * The UI allows stepping through this entry's markers grouped by the key. - * </p> - * <p> - * This interface is not intended to be implemented by clients. - * </p> - */ -public interface ISearchResultViewEntry { - - /** - * Returns the key by which this entry's markers - * are logically grouped. A line in a text could be such a key. - * Clients supply this key as a parameter to <code>ISearchResultView.addMatch</code>. - * - * @return the common resource of this entry's markers - * @see ISearchResultView#addMatch - */ - public Object getGroupByKey(); - - /** - * Returns the resource to which this entry's markers are attached. - * This is a convenience method for <code>getSelectedMarker().getResource()</code>. - * - * @return the common resource of this entry's markers - */ - public IResource getResource(); - - /** - * Returns the number of markers grouped by this entry. - * - * @return the number of markers - */ - public int getMatchCount(); - - /** - * Returns the selected marker of this entry, or the first one - * if no marker is selected. - * A search results view entry can group markers - * which the UI allows the user to step through them while - * this entry remains selected. - * - * @return the selected marker inside this entry, or - * <code>null</code> if the entry has no markers - */ - public IMarker getSelectedMarker(); -} diff --git a/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java b/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java deleted file mode 100644 index 6525942c003..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/SearchUI.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.search.ui; - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.ui.IWorkbenchWindow; - -import org.eclipse.search.internal.ui.OpenSearchDialogAction; -import org.eclipse.search.internal.ui.SearchPlugin; -import org.eclipse.search.internal.ui.SearchPluginImages; -import org.eclipse.search.internal.ui.SearchPreferencePage; - -/** - * The central class for access to the Search Plug-in's User Interface. - * This class cannot be instantiated; all functionality is provided by - * static methods. - * - * Features provided: - * <ul> - * <li>convenient access to the search result view of the active workbench - * window.</li> - * </ul> - * - * @see ISearchResultView - */ -public final class SearchUI { - - /** - * Search Plug-in Id (value <code>"org.eclipse.search"</code>). - */ - public static final String PLUGIN_ID= "org.eclipse.search"; //$NON-NLS-1$ - - /** - * Search marker type (value <code>"org.eclipse.search.searchmarker"</code>). - * - * @see org.eclipse.core.resources.IMarker - */ - public static final String SEARCH_MARKER= PLUGIN_ID + ".searchmarker"; //$NON-NLS-1$ - - /** - * Line marker attribute (value <code>"line"</code>) - * The value of the marker attribute is the line which contains the text search match. - * - * @see org.eclipse.core.resources.IMarker#getAttribute - */ - public static final String LINE= "line"; //$NON-NLS-1$ - - /** - * Potential match marker attribute - * (value <code>"potentialMatch"</code>). - * <p> - * This optional marker attribute tells whether a marker is - * a potential or an exact match. - * The marker is considered an exact match if the attribute is missing. - * </p> - * <p> - * Potential matches are shown with a different background color in - * the Search view. The color can be changed in the Search preferences. - * </p> - * - * @see org.eclipse.core.resources.IMarker#getAttribute - * @since 2.0 - */ - public static final String POTENTIAL_MATCH= "potentialMatch"; //$NON-NLS-1$ - - /** - * Id of the Search result view - * (value <code>"org.eclipse.search.SearchResultView"</code>). - */ - public static final String SEARCH_RESULT_VIEW_ID= "org.eclipse.search.SearchResultView"; //$NON-NLS-1$ - - /** - * Id of the Search action set - * (value <code>"org.eclipse.search.searchActionSet"</code>). - * - * @since 2.0 - */ - public static final String ACTION_SET_ID= PLUGIN_ID + ".searchActionSet"; //$NON-NLS-1$ - - /** - * Activates the search result view in the active page of the - * active workbench window. This call has no effect (but returns <code>true</code> - * if the search result view is already activated. - * - * @return <code>true</code> if the search result view could be activated - */ - public static boolean activateSearchResultView() { - return SearchPlugin.activateSearchResultView(); - } - - /** - * Opens the search dialog. - * If <code>pageId</code> is specified and a corresponding page - * is found then it is brought to top. - * - * @param pageId the page to select or <code>null</code> - * if the best fitting page should be selected - * @since 2.0 - */ - public static void openSearchDialog(IWorkbenchWindow window, String pageId) { - new OpenSearchDialogAction(window, pageId).run(); - } - - /** - * Returns the search result view of the active page of the - * active workbench window. - * - * @return the search result view or <code>null</code> - * if there is no active search result view - */ - public static ISearchResultView getSearchResultView() { - return SearchPlugin.getSearchResultView(); - } - - /** - * Returns the shared search marker image. - * Normally, editors show this icon in their vertical ruler. - * This image is owned by the search UI plug-in and must not be disposed - * by clients. - * - * @return the shared image - */ - public static Image getSearchMarkerImage() { - return SearchPluginImages.get(SearchPluginImages.IMG_OBJ_SEARCHMARKER); - } - - /** - * Returns the preference whether editors should be reused - * when showing search results. - * - * The goto action can decide to use or ignore this preference. - * - * @return <code>true</code> if editors should be reused for showing search results - * @since 2.0 - */ - public static boolean reuseEditor() { - return SearchPreferencePage.isEditorReused(); - } - - /** - * Returns the preference whether a search engine is - * allowed to report potential matches or not. - * <p> - * Search engines which can report inexact matches must - * respect this preference i.e. they should not report - * inexact matches if this method returns <code>true</code> - * </p> - * @return <code>true</code> if search engine must not report inexact matches - * @since 2.1 - */ - public static boolean arePotentialMatchesIgnored() { - return SearchPreferencePage.arePotentialMatchesIgnored(); - } - - /** - * Block instantiation. - */ - private SearchUI() { - } -} diff --git a/org.eclipse.search/search/org/eclipse/search/ui/package.html b/org.eclipse.search/search/org/eclipse/search/ui/package.html deleted file mode 100644 index f92908814cb..00000000000 --- a/org.eclipse.search/search/org/eclipse/search/ui/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.75 [en] (WinNT; U) [Netscape]"> - <title>Package-level Javadoc</title> -</head> -<body> -Provides classes and interfaces for search pages. -New search dialog pages can be contributed via a plug-in extension point. -This package provides the interfaces and classes to implement these dialog -pages and offers hooks to populate the search result view. -<h2> -Package Specification</h2> -Each search dialog page must implement <tt>ISearchPage</tt>. A search page -has access to its container (<tt>ISearchPageContainer</tt>) to modify search -dialog properties. The class <tt>SearchUI</tt> can activate the search -results view and provide access to the active search results view (<tt>ISearchResultView</tt>). -<p>It is the clients responsibility to create a marker for each match and -then report the match to the search result view together with a key (<tt>groupByKey</tt>). -Each key corresponds to a search result view entry (<tt>ISearchResultViewEntry</tt>) -which allows to step through the markers grouped by the key. -</body> -</html> diff --git a/org.eclipse.text/.classpath b/org.eclipse.text/.classpath deleted file mode 100644 index d8b3fa0d8f2..00000000000 --- a/org.eclipse.text/.classpath +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/org.eclipse.text/.cvsignore b/org.eclipse.text/.cvsignore deleted file mode 100644 index c5e82d74585..00000000000 --- a/org.eclipse.text/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin
\ No newline at end of file diff --git a/org.eclipse.text/.project b/org.eclipse.text/.project deleted file mode 100644 index 9e0b25af586..00000000000 --- a/org.eclipse.text/.project +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.text</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/org.eclipse.text/build.properties b/org.eclipse.text/build.properties deleted file mode 100644 index 04e9be9a51b..00000000000 --- a/org.eclipse.text/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -bin.includes = plugin.properties,\ - plugin.xml,\ - *.jar -source.text.jar = src/ diff --git a/org.eclipse.text/plugin.properties b/org.eclipse.text/plugin.properties deleted file mode 100644 index 460170dca21..00000000000 --- a/org.eclipse.text/plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -pluginName= Text -providerName= Eclipse.org diff --git a/org.eclipse.text/plugin.xml b/org.eclipse.text/plugin.xml deleted file mode 100644 index ae9d701e3f1..00000000000 --- a/org.eclipse.text/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<plugin - id="org.eclipse.text" - name="%pluginName" - version="2.1.0" - provider-name="%providerName"> - - <runtime> - <library name="text.jar"> - <export name="*"/> - </library> - </runtime> - -</plugin> diff --git a/org.eclipse.text/scripts/exportplugin.xml b/org.eclipse.text/scripts/exportplugin.xml deleted file mode 100644 index 870cc45dc6b..00000000000 --- a/org.eclipse.text/scripts/exportplugin.xml +++ /dev/null @@ -1,28 +0,0 @@ -<project name="Export Text" default="export" basedir=".."> - <target name="init"> - <tstamp/> - <property name="destdir" value="../../plugin-export" /> - <property name="plugin" value="org.eclipse.text" /> - <property name="version" value="_2.1.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}/text.jar" - basedir="bin" - /> - <copy file="plugin.xml" todir="${dest}"/> - <copy file="plugin.properties" todir="${dest}"/> - <zip zipfile="${dest}/textsrc.zip"> - <fileset dir="src" /> - </zip> - </target> -</project> diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java deleted file mode 100644 index 8e822aa7e68..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java +++ /dev/null @@ -1,1177 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - - -/** - * Abstract implementation of <code>IDocument</code>. - * Implements the complete contract of <code>IDocument</code> and <code>IDocumentExtension</code>. - * An <code>AbstractDocument</code> supports the following implementation plug-ins: - * <ul> - * <li> a text store for storing and managing the document's content - * <li> a line tracker to map character positions to line numbers and vice versa - * </ul> - * This class must be subclassed. Subclasses must configure which implementation - * plug-ins the document should use. Subclasses are not intended to overwrite existing methods. - * - * @see IDocument - * @see ITextStore - * @see ILineTracker - */ -public abstract class AbstractDocument implements IDocument, IDocumentExtension { - - /** The document's text store */ - private ITextStore fStore; - /** The document's line tracker */ - private ILineTracker fTracker; - /** The document's partitioner */ - private IDocumentPartitioner fDocumentPartitioner; - /** - * The document's partitioner casted to <code>IDocumentPartitionerExtension</code>. - * @since 2.0 - */ - private IDocumentPartitionerExtension fDocumentPartitionerExtension; - /** The registered document listeners */ - private List fDocumentListeners; - /** The registered prenotified document listeners */ - private List fPrenotifiedDocumentListeners; - /** The registered document partitioning listeners */ - private List fDocumentPartitioningListeners; - /** All positions managed by the document */ - private Map fPositions; - /** All registered document position updaters */ - private List fPositionUpdaters; - - /** - * The list of post notification changes - * @since 2.0 - */ - private List fPostNotificationChanges; - /** - * The reentrance count for post notification changes. - * @since 2.0 - */ - private int fReentranceCount= 0; - /** - * Indicates whether post notification change processing has been stopped. - * @since 2.0 - */ - private int fStoppedCount= 0; - - /** - * The default constructor does not perform any configuration - * but leaves it to the clients who must first initialize the - * implementation plug-ins and then call <code>completeInitialization</code>. - * Results in the construction of an empty document. - */ - protected AbstractDocument() { - } - - - //--- accessor to fields ------------------------------- - - /** - * Returns the document's text store. Assumes that the - * document has been initialized with a text store. - * - * @return the document's text store - */ - protected ITextStore getStore() { - Assert.isNotNull(fStore); - return fStore; - } - - /** - * Returns the document's line tracker. Assumes that the - * document has been initialized with a line tracker. - * - * @return the document's line tracker - */ - protected ILineTracker getTracker() { - Assert.isNotNull(fTracker); - return fTracker; - } - - /** - * Returns the document's document listeners. - * - * @return the document's document listeners - */ - protected List getDocumentListeners() { - return fDocumentListeners; - } - - /** - * Returns the document's partitioning listeners . - * - * @return the document's partitioning listeners - */ - protected List getDocumentPartitioningListeners() { - return fDocumentPartitioningListeners; - } - - /** - * Returns all positions managed by the document grouped by category. - * - * @return the document's positions - */ - protected Map getDocumentManagedPositions() { - return fPositions; - } - - /* - * @see IDocument#getDocumentPartitioner - */ - public IDocumentPartitioner getDocumentPartitioner() { - return fDocumentPartitioner; - } - - - - //--- implementation configuration interface ------------ - - /** - * Sets the document's text store. - * Must be called first inside the constructor. - * - * @param store the document's text store - */ - protected void setTextStore(ITextStore store) { - fStore= store; - } - - /** - * Sets the document's line tracker. - * Must be called first inside the constructor. - * - * @param tracker the document's line tracker - */ - protected void setLineTracker(ILineTracker tracker) { - fTracker= tracker; - } - - /* - * @see IDocument#setDocumentPartitioner - */ - public void setDocumentPartitioner(IDocumentPartitioner partitioner) { - fDocumentPartitioner= partitioner; - if (fDocumentPartitioner instanceof IDocumentPartitionerExtension) - fDocumentPartitionerExtension= (IDocumentPartitionerExtension) fDocumentPartitioner; - - fireDocumentPartitioningChanged(new Region(0, getLength())); - } - - /** - * Initializes document listeners, positions, and position updaters. - * Must be called inside the constructor after the implementation plug-ins - * have been set. - */ - protected void completeInitialization() { - - fPositions= new HashMap(); - fPositionUpdaters= new ArrayList(); - fDocumentListeners= new ArrayList(); - fPrenotifiedDocumentListeners= new ArrayList(); - fDocumentPartitioningListeners= new ArrayList(); - - addPositionCategory(DEFAULT_CATEGORY); - addPositionUpdater(new DefaultPositionUpdater(DEFAULT_CATEGORY)); - } - - - //------------------------------------------------------- - - /* - * @see IDocument#addDocumentListener - */ - public void addDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - if (! fDocumentListeners.contains(listener)) - fDocumentListeners.add(listener); - } - - /* - * @see IDocument#removeDocumentListener - */ - public void removeDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - fDocumentListeners.remove(listener); - } - - /* - * @see IDocument#addPrenotifiedDocumentListener(IDocumentListener) - */ - public void addPrenotifiedDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - if (! fPrenotifiedDocumentListeners.contains(listener)) - fPrenotifiedDocumentListeners.add(listener); - } - - /* - * @see IDocument#removePrenotifiedDocumentListener(IDocumentListener) - */ - public void removePrenotifiedDocumentListener(IDocumentListener listener) { - Assert.isNotNull(listener); - fPrenotifiedDocumentListeners.remove(listener); - } - - /* - * @see IDocument#addDocumentPartitioningListener - */ - public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) { - Assert.isNotNull(listener); - if (! fDocumentPartitioningListeners.contains(listener)) - fDocumentPartitioningListeners.add(listener); - } - - /* - * @see IDocument#removeDocumentPartitioningListener - */ - public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) { - Assert.isNotNull(listener); - fDocumentPartitioningListeners.remove(listener); - } - - /* - * @see IDocument#addPosition - */ - public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { - - if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength())) - throw new BadLocationException(); - - if (category == null) - throw new BadPositionCategoryException(); - - List list= (List) fPositions.get(category); - if (list == null) - throw new BadPositionCategoryException(); - - list.add(computeIndexInPositionList(list, position.offset), position); - } - - /* - * @see IDocument#addPosition - */ - public void addPosition(Position position) throws BadLocationException { - try { - addPosition(DEFAULT_CATEGORY, position); - } catch (BadPositionCategoryException e) { - } - } - - /* - * @see IDocument#addPositionCategory - */ - public void addPositionCategory(String category) { - - if (category == null) - return; - - if (!containsPositionCategory(category)) - fPositions.put(category, new ArrayList()); - } - - /* - * @see IDocument#addPositionUpdater - */ - public void addPositionUpdater(IPositionUpdater updater) { - insertPositionUpdater(updater, fPositionUpdaters.size()); - } - - /* - * @see IDocument#containsPosition - */ - public boolean containsPosition(String category, int offset, int length) { - - if (category == null) - return false; - - List list= (List) fPositions.get(category); - if (list == null) - return false; - - int size= list.size(); - if (size == 0) - return false; - - int index= computeIndexInPositionList(list, offset); - if (index < size) { - Position p= (Position) list.get(index); - while (p != null && p.offset == offset) { - if (p.length == length) - return true; - ++ index; - p= (index < size) ? (Position) list.get(index) : null; - } - } - - return false; - } - - /* - * @see IDocument#containsPositionCategory - */ - public boolean containsPositionCategory(String category) { - if (category != null) - return fPositions.containsKey(category); - return false; - } - - - /** - * Computes the index in the list of positions at which a position with the given - * offset would be inserted. The position is supposed to become the first in this list - * of all positions with the same offset. - * - * @param positions the list in which the index is computed - * @param offset the offset for which the index is computed - * @return the computed index - * - * @see IDocument#computeIndexInCategory(String, int) - */ - protected int computeIndexInPositionList(List positions, int offset) { - - if (positions.size() == 0) - return 0; - - int left= 0; - int right= positions.size() -1; - int mid= 0; - Position p= null; - - while (left < right) { - - mid= (left + right) / 2; - - p= (Position) positions.get(mid); - if (offset < p.getOffset()) { - if (left == mid) - right= left; - else - right= mid -1; - } else if (offset > p.getOffset()) { - if (right == mid) - left= right; - else - left= mid +1; - } else if (offset == p.getOffset()) { - left= right= mid; - } - - } - - int pos= left; - p= (Position) positions.get(pos); - if (offset > p.getOffset()) { - // append to the end - pos++; - } else { - // entry will became the first of all entries with the same offset - do { - --pos; - if (pos < 0) - break; - p= (Position) positions.get(pos); - } while (offset == p.getOffset()); - ++pos; - } - - Assert.isTrue(0 <= pos && pos <= positions.size()); - - return pos; - } - - - /* - * @see IDocument#computeIndexInCategory - */ - public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException { - - if (0 > offset || offset > getLength()) - throw new BadLocationException(); - - List c= (List) fPositions.get(category); - if (c == null) - throw new BadPositionCategoryException(); - - return computeIndexInPositionList(c, offset); - } - - /** - * Fires the document partitioning changed notification to all registered - * document partitioning listeners. Uses a robust iterator. - * @deprecated use <code>fireDocumentPartitioningChanged(IRegion)</code> instead - */ - protected void fireDocumentPartitioningChanged() { - - if (fDocumentPartitioningListeners != null && fDocumentPartitioningListeners.size() > 0) { - - List list= new ArrayList(fDocumentPartitioningListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentPartitioningListener l= (IDocumentPartitioningListener) e.next(); - l.documentPartitioningChanged(this); - } - } - } - - /** - * Fires the document partitioning changed notification to all registered - * document partitioning listeners. Uses a robust iterator. - * - * @param region the region in which partitioning has changed - * @see IDocumentPartitioningListenerExtension - * @since 2.0 - */ - protected void fireDocumentPartitioningChanged(IRegion region) { - - if (fDocumentPartitioningListeners != null && fDocumentPartitioningListeners.size() > 0) { - - List list= new ArrayList(fDocumentPartitioningListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentPartitioningListener l= (IDocumentPartitioningListener) e.next(); - if (l instanceof IDocumentPartitioningListenerExtension) - ((IDocumentPartitioningListenerExtension) l).documentPartitioningChanged(this, region); - else - l.documentPartitioningChanged(this); - } - } - } - - /** - * Fires the given document event to all registers document listeners informing them - * about the forthcoming document manipulation. Uses a robust iterator. - * - * @param event the event to be sent out - */ - protected void fireDocumentAboutToBeChanged(DocumentEvent event) { - - // IDocumentExtension - if (fReentranceCount == 0) - flushPostNotificationChanges(); - - if (fDocumentPartitioner != null) - fDocumentPartitioner.documentAboutToBeChanged(event); - - if (fPrenotifiedDocumentListeners.size() > 0) { - - List list= new ArrayList(fPrenotifiedDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentAboutToBeChanged(event); - } - } - - if (fDocumentListeners.size() > 0) { - - List list= new ArrayList(fDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentAboutToBeChanged(event); - } - } - } - - /** - * Updates document partitioning and document positions according to the - * specification given by the document event. - * - * @param event the document event describing the change to which structures must be adapted - */ - protected void updateDocumentStructures(DocumentEvent event) { - boolean partitioningChanged= false; - IRegion changedRegion= null; - - if (fDocumentPartitioner != null) { - if (fDocumentPartitionerExtension != null) { - changedRegion= fDocumentPartitionerExtension.documentChanged2(event); - partitioningChanged= (changedRegion != null); - } else - partitioningChanged= fDocumentPartitioner.documentChanged(event); - } - - if (fPositions.size() > 0) - updatePositions(event); - - if (partitioningChanged) - fireDocumentPartitioningChanged(changedRegion); - } - - /** - * Updates the internal document structures and informs all document listeners. - * Uses a robust iterator. <p> - * Executes all registered post notification replace operation. - * - * @param event the document event to be sent out - * @see IDocumentExtension - */ - protected void fireDocumentChanged(DocumentEvent event) { - updateDocumentStructures(event); - - if (fPrenotifiedDocumentListeners.size() > 0) { - - List list= new ArrayList(fPrenotifiedDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentChanged(event); - } - } - - if (fDocumentListeners.size() > 0) { - - List list= new ArrayList(fDocumentListeners); - Iterator e= list.iterator(); - while (e.hasNext()) { - IDocumentListener l= (IDocumentListener) e.next(); - l.documentChanged(event); - } - } - - // IDocumentExtension - ++ fReentranceCount; - try { - if (fReentranceCount == 1) - executePostNotificationChanges(); - } finally { - -- fReentranceCount; - } - } - - /* - * @see IDocument#getChar - */ - public char getChar(int pos) throws BadLocationException { - if ((0 > pos) || (pos >= getLength())) - throw new BadLocationException(); - return getStore().get(pos); - } - - /* - * @see IDocument#getContentType - */ - public String getContentType(int offset) throws BadLocationException { - if ((0 > offset) || (offset > getLength())) - throw new BadLocationException(); - - if (fDocumentPartitioner == null) - return DEFAULT_CONTENT_TYPE; - - return fDocumentPartitioner.getContentType(offset); - } - - /* - * @see IDocument#getLegalContentTypes - */ - public String[] getLegalContentTypes() { - if (fDocumentPartitioner == null) - return new String[] { DEFAULT_CONTENT_TYPE }; - return fDocumentPartitioner.getLegalContentTypes(); - } - - /* - * @see IDocument#getLength - */ - public int getLength() { - return getStore().getLength(); - } - - /* - * @see IDocument#getLineDelimiter - */ - public String getLineDelimiter(int line) throws BadLocationException { - return getTracker().getLineDelimiter(line); - } - - /* - * @see IDocument#getLegalLineDelimiters - */ - public String[] getLegalLineDelimiters() { - return getTracker().getLegalLineDelimiters(); - } - - /* - * @see IDocument#getLineLength - */ - public int getLineLength(int line) throws BadLocationException { - return getTracker().getLineLength(line); - } - - /* - * @see IDocument#getLineOfOffset - */ - public int getLineOfOffset(int pos) throws BadLocationException { - return getTracker().getLineNumberOfOffset(pos); - } - - /* - * @see IDocument#getLineOffset - */ - public int getLineOffset(int line) throws BadLocationException { - return getTracker().getLineOffset(line); - } - - /* - * @see IDocument#getLineInformation - */ - public IRegion getLineInformation(int line) throws BadLocationException { - return getTracker().getLineInformation(line); - } - - /* - * @see IDocument#getLineInformationOfOffset - */ - public IRegion getLineInformationOfOffset(int offset) throws BadLocationException { - return getTracker().getLineInformationOfOffset(offset); - } - - /* - * @see IDocument#getNumberOfLines - */ - public int getNumberOfLines() { - return getTracker().getNumberOfLines(); - } - - /* - * @see IDocument#getNumberOfLines(int, int) - */ - public int getNumberOfLines(int offset, int length) throws BadLocationException { - return getTracker().getNumberOfLines(offset, length); - } - - /* - * @see IDocument#computeNumberOfLines(String) - */ - public int computeNumberOfLines(String text) { - return getTracker().computeNumberOfLines(text); - } - - /* - * @see IDocument#getPartition - */ - public ITypedRegion getPartition(int offset) throws BadLocationException { - if ((0 > offset) || (offset > getLength())) - throw new BadLocationException(); - - if (fDocumentPartitioner == null) - return new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE); - - return fDocumentPartitioner.getPartition(offset); - } - - /* - * @see IDocument#computePartitioning - */ - public ITypedRegion[] computePartitioning(int offset, int length) throws BadLocationException { - if ((0 > offset) || (0 > length) || (offset + length > getLength())) - throw new BadLocationException(); - - if (fDocumentPartitioner == null) - return new TypedRegion[] { new TypedRegion(offset, length, DEFAULT_CONTENT_TYPE) }; - - return fDocumentPartitioner.computePartitioning(offset, length); - } - - /* - * @see IDocument#getPositions - */ - public Position[] getPositions(String category) throws BadPositionCategoryException { - - if (category == null) - throw new BadPositionCategoryException(); - - List c= (List) fPositions.get(category); - if (c == null) - throw new BadPositionCategoryException(); - - Position[] positions= new Position[c.size()]; - c.toArray(positions); - return positions; - } - - /* - * @see IDocument#getPositionCategories - */ - public String[] getPositionCategories() { - String[] categories= new String[fPositions.size()]; - Iterator keys= fPositions.keySet().iterator(); - for (int i= 0; i < categories.length; i++) - categories[i]= (String) keys.next(); - return categories; - } - - /* - * @see IDocument#getPositionUpdaters - */ - public IPositionUpdater[] getPositionUpdaters() { - IPositionUpdater[] updaters= new IPositionUpdater[fPositionUpdaters.size()]; - fPositionUpdaters.toArray(updaters); - return updaters; - } - - /* - * @see IDocument#get - */ - public String get() { - return getStore().get(0, getLength()); - } - - /* - * @see IDocument#get - */ - public String get(int pos, int length) throws BadLocationException { - int myLength= getLength(); - if ((0 > pos) || (0 > length) || (pos + length > myLength)) - throw new BadLocationException(); - return getStore().get(pos, length); - } - - /* - * @see IDocument#insertPositionUpdater - */ - public void insertPositionUpdater(IPositionUpdater updater, int index) { - - for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { - if (fPositionUpdaters.get(i) == updater) - return; - } - - if (index == fPositionUpdaters.size()) - fPositionUpdaters.add(updater); - else - fPositionUpdaters.add(index, updater); - } - - /* - * @see IDocument#removePosition - */ - public void removePosition(String category, Position position) throws BadPositionCategoryException { - - if (position == null) - return; - - if (category == null) - throw new BadPositionCategoryException(); - - List c= (List) fPositions.get(category); - if (c == null) - throw new BadPositionCategoryException(); - - // remove based on identity not equality - int size= c.size(); - for (int i= 0; i < size; i++) { - if (position == c.get(i)) { - c.remove(i); - return; - } - } - } - - /* - * @see IDocument#removePosition - */ - public void removePosition(Position position) { - try { - removePosition(DEFAULT_CATEGORY, position); - } catch (BadPositionCategoryException e) { - } - } - - /* - * @see IDocument#removePositionCategory - */ - public void removePositionCategory(String category) throws BadPositionCategoryException { - - if (category == null) - return; - - if ( !containsPositionCategory(category)) - throw new BadPositionCategoryException(); - - fPositions.remove(category); - } - - /* - * @see IDocument#removePositionUpdater - */ - public void removePositionUpdater(IPositionUpdater updater) { - for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) { - if (fPositionUpdaters.get(i) == updater) { - fPositionUpdaters.remove(i); - return; - } - } - } - - /* - * @see IDocument#replace - */ - public void replace(int pos, int length, String text) throws BadLocationException { - if ((0 > pos) || (0 > length) || (pos + length > getLength())) - throw new BadLocationException(); - - DocumentEvent e= new DocumentEvent(this, pos, length, text); - fireDocumentAboutToBeChanged(e); - - getStore().replace(pos, length, text); - getTracker().replace(pos, length, text); - - fireDocumentChanged(e); - } - - /* - * @see IDocument#set - */ - public void set(String text) { - int length= getStore().getLength(); - DocumentEvent e= new DocumentEvent(this, 0, length, text); - fireDocumentAboutToBeChanged(e); - - getStore().set(text); - getTracker().set(text); - - fireDocumentChanged(e); - } - - /** - * Updates all positions of all categories to the change - * described by the document event. All registered document - * updaters are called in the sequence they have been arranged. - * Uses a robust iterator. - * - * @param event the document event describing the change to which to adapt the positions - */ - protected void updatePositions(DocumentEvent event) { - List list= new ArrayList(fPositionUpdaters); - Iterator e= list.iterator(); - while (e.hasNext()) { - IPositionUpdater u= (IPositionUpdater) e.next(); - u.update(event); - } - } - - /* - * @see IDocument#search - */ - public int search(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException { - - if (findString == null || findString.length() == 0) - return -1; - - ITextStore store= getStore(); - - if (startPosition < -1 || startPosition > store.getLength()) - throw new BadLocationException(); - - if (!caseSensitive) - findString= findString.toLowerCase(); - - char[] fs= new char[findString.length()]; - findString.getChars(0, fs.length, fs, 0); - - - if (forwardSearch) { - if (startPosition == -1) - startPosition= 0; - int end= getLength(); - while (startPosition < end) { - int pos= indexOf(store, fs, startPosition, caseSensitive); - if (!wholeWord || pos == -1 || isWholeWord(store, pos, pos + fs.length)) { - return pos; - } - startPosition= pos + 1; - } - } else { - if (startPosition == -1) - startPosition= getLength(); - while (startPosition >= 0) { - int pos= lastIndexOf(store, fs, startPosition, caseSensitive); - if (!wholeWord || pos == -1 || isWholeWord(store, pos, pos + fs.length)) { - return pos; - } - startPosition= pos - 1; - } - } - return -1; - } - - /** - * Returns the first index greater than <code>fromIndex</code> at which <code>str</code> - * can be found in the <code>store</code>. - * - * @param store the text store to search - * @param str the string to search - * @param fromIndex the start offset - * @param caseSensitive <code>true</code> if capitalization should be honored, <code>false</code> otherwise - * @return the offset greater than the start offset at which the search string has been found - */ - static private int indexOf(ITextStore store, char[] str, int fromIndex, boolean caseSensitive) { - int count= store.getLength(); - - if (fromIndex >= count) - return -1; - - if (fromIndex < 0) - fromIndex= 0; - - int strLen= str.length; - if (strLen == 0) // empty string always matches - return fromIndex; - - char first= str[0]; - int i= fromIndex; - int max= count - strLen; - - restart: - while (true) { - - // Look for first character - if (caseSensitive) { - while (i <= max && store.get(i) != first) - i++; - } else { - while (i <= max && Character.toLowerCase(store.get(i)) != first) - i++; - } - - if (i > max) - return -1; - - // Found first character - int j= i + 1; - int end= j + strLen - 1; - int k= 1; - if (caseSensitive) { - while (j < end) { - if (store.get(j++) != str[k++]) { - i++; - continue restart; - } - } - } else { - while (j < end) { - if (Character.toLowerCase(store.get(j++)) != str[k++]) { - i++; - continue restart; - } - } - } - - return i; // Found - } - } - - /** - * Returns the first index smaller than <code>fromIndex</code> at which <code>str</code> - * can be found in the <code>store</code>. - * - * @param store the text store to search - * @param str the string to search - * @param fromIndex the start offset - * @param caseSensitive <code>true</code> if capitalization should be honored, <code>false</code> otherwise - * @return the offset smaller than the start offset at which the search string has been found - */ - static private int lastIndexOf(ITextStore store, char[] str, int fromIndex, boolean caseSensitive) { - - if (fromIndex < 0) - return -1; - - int count= store.getLength(); - int strLen= str.length; - int rightIndex= count - strLen; - - if (fromIndex > rightIndex) - fromIndex= rightIndex; - - if (strLen == 0) // empty string always matches - return fromIndex; - - int strLastIndex= strLen - 1; - char strLastChar= str[strLastIndex]; - int min= strLen - 1; - int i= min + fromIndex; - - restart: - while (true) { - - // Look for the last character - if (caseSensitive) { - while (i >= min && store.get(i) != strLastChar) - i--; - } else { - while (i >= min && Character.toLowerCase(store.get(i)) != strLastChar) - i--; - } - - if (i < min) - return -1; - - // Found last character - int j= i - 1; - int start= j - (strLen - 1); - int k= strLastIndex - 1; - - if (caseSensitive) { - while (j > start) { - if (store.get(j--) != str[k--]) { - i--; - continue restart; - } - } - } else { - while (j > start) { - if (Character.toLowerCase(store.get(j--)) != str[k--]) { - i--; - continue restart; - } - } - } - - return start + 1; /* Found whole string. */ - } - } - - /** - * Tests if the substring is a whole word. - * - * @param store the store in which to find the string - * @param from the substring start offset - * @param to the substring endoffset - * @return <code>true</code> if the string is a whole word, otherwise <code>false</code> - */ - private static boolean isWholeWord(ITextStore store, int from, int to) { - - if (from > 0) { - char ch= store.get(from-1); - if (Character.isLetterOrDigit(ch) || ch == '_') { - return false; - } - } - if (to < store.getLength()) { - char ch= store.get(to); - if (Character.isLetterOrDigit(ch) || ch == '_' ) { - return false; - } - } - return true; - } - - - // ---------- implementation of IDocumentExtension -------------- - - /** - * Inner class to bundle a registered post notifcation replace operation together with its - * owner. - * - * @since 2.0 - */ - static private class RegisteredReplace { - /** The owner of this replace operation. */ - IDocumentListener fOwner; - /** The replace operation */ - IDocumentExtension.IReplace fReplace; - - /** - * Creates a new bundle object. - */ - RegisteredReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { - fOwner= owner; - fReplace= replace; - } - }; - - /** - * Flushs all registered post notification changes. - * - * @since 2.0 - */ - private void flushPostNotificationChanges() { - if (fPostNotificationChanges != null) - fPostNotificationChanges.clear(); - } - - /** - * Executes all registered post notification changes. The process is - * repeated until no new post notification changes are added. - * - * @since 2.0 - */ - private void executePostNotificationChanges() { - - if (fStoppedCount > 0) - return; - - while (fPostNotificationChanges != null) { - List changes= fPostNotificationChanges; - fPostNotificationChanges= null; - - Iterator e= changes.iterator(); - while (e.hasNext()) { - RegisteredReplace replace = (RegisteredReplace) e.next(); - replace.fReplace.perform(this, replace.fOwner); - } - } - } - - /* - * @see IDocumentExtension#registerPostNotificationReplace(IDocumentListener, IDocumentExtension.IReplace) - * @since 2.0 - */ - public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { - if (fPostNotificationChanges == null) - fPostNotificationChanges= new ArrayList(1); - fPostNotificationChanges.add(new RegisteredReplace(owner, replace)); - } - - /* - * @see IDocumentExtension#stopPostNotificationProcessing() - * @since 2.0 - */ - public void stopPostNotificationProcessing() { - ++ fStoppedCount; - } - - /* - * @see IDocumentExtension#resumePostNotificationProcessing() - * @since 2.0 - */ - public void resumePostNotificationProcessing() { - -- fStoppedCount; - if (fStoppedCount == 0 && fReentranceCount == 0) - executePostNotificationChanges(); - } - - /* - * @see IDocumentExtension#startSequentialRewrite(boolean) - * @since 2.0 - */ - public void startSequentialRewrite(boolean normalized) { - } - - /* - * @see IDocumentExtension#stopSequentialRewrite() - * @since 2.0 - */ - public void stopSequentialRewrite() { - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java deleted file mode 100644 index f74f3051e6b..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java +++ /dev/null @@ -1,502 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.List; - - - -/** - * Abstract implementation of <code>ILineTracker</code>. It lets the - * definition of line delimiters to subclasses. Assuming that '\n' is - * the only line delimiter, this abstract implementation defines the - * following line scheme: - * <ul> - * <li> "" -> [0,0] - * <li> "a" -> [0,1] - * <li> "\n" -> [0,1], [1,0] - * <li> "a\n" -> [0,2], [2,0] - * <li> "a\nb" -> [0,2], [2,1] - * <li> "a\nbc\n" -> [0,2], [2,3], [5,0] - * </ul> - * This class must be subclassed. - */ -public abstract class AbstractLineTracker implements ILineTracker { - - - /** - * Combines the information of the occurence of a line delimiter. - * <code>delimiterIndex</code> is the index where a line delimiter - * starts, whereas <code>delimiterLength</code>, indicates the length - * of the delimiter. - */ - protected static class DelimiterInfo { - public int delimiterIndex; - public int delimiterLength; - public String delimiter; - }; - - - /** The line information */ - private List fLines= new ArrayList(); - /** The length of the tracked text */ - private int fTextLength; - - - /** - * Creates a new line tracker. - */ - protected AbstractLineTracker() { - } - - /** - * Binary search for the line at a given offset. - * - * @param offset the offset whose line should be found - * @return the line of the offset - */ - private int findLine(int offset) { - - if (fLines.size() == 0) - return -1; - - int left= 0; - int right= fLines.size() -1; - int mid= 0; - Line line= null; - - while (left < right) { - - mid= (left + right) / 2; - - line= (Line) fLines.get(mid); - if (offset < line.offset) { - if (left == mid) - right= left; - else - right= mid -1; - } else if (offset > line.offset) { - if (right == mid) - left= right; - else - left= mid +1; - } else if (offset == line.offset) { - left= right= mid; - } - } - - line= (Line) fLines.get(left); - if (line.offset > offset) - -- left; - return left; - } - - /** - * Returns the number of lines covered by the specified text range. - * - * @param startLine the line where the text range starts - * @param offset the start offset of the text range - * @param length the length of the text range - * @return the number of lines covered by this text range - * @exception BadLocationException if range is undefined in this tracker - */ - private int getNumberOfLines(int startLine, int offset, int length) throws BadLocationException { - - if (length == 0) - return 1; - - int target= offset + length; - - Line l= (Line) fLines.get(startLine); - - if (l.delimiter == null) - return 1; - - if (l.offset + l.length > target) - return 1; - - if (l.offset + l.length == target) - return 2; - - return getLineNumberOfOffset(target) - startLine + 1; - } - - /* - * @see ILineTracker#getLineLength - */ - public int getLineLength(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0 || lines == line) - return 0; - - Line l= (Line) fLines.get(line); - return l.length; - } - - /* - * @see ILineTracker#getLineNumberOfOffset - */ - public int getLineNumberOfOffset(int position) throws BadLocationException { - - if (position > fTextLength) - throw new BadLocationException(); - - if (position == fTextLength) { - - int lastLine= fLines.size() - 1; - if (lastLine < 0) - return 0; - - Line l= (Line) fLines.get(lastLine); - return (l.delimiter != null ? lastLine + 1 : lastLine); - } - - return findLine(position); - } - - /* - * @see ILineTracker#getLineInformationOfOffset - */ - public IRegion getLineInformationOfOffset(int position) throws BadLocationException { - if (position > fTextLength) - throw new BadLocationException(); - - if (position == fTextLength) { - int size= fLines.size(); - if (size == 0) - return new Region(0, 0); - Line l= (Line) fLines.get(size - 1); - return (l.delimiter != null ? new Line(fTextLength, 0) : new Line(fTextLength - l.length, l.length)); - } - - return getLineInformation(findLine(position)); - } - - /* - * @see ILineTracker#getLineInformation - */ - public IRegion getLineInformation(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0) - return new Line(0, 0); - - if (line == lines) { - Line l= (Line) fLines.get(line - 1); - return new Line(l.offset + l.length, 0); - } - - Line l= (Line) fLines.get(line); - return (l.delimiter != null ? new Line(l.offset, l.length - l.delimiter.length()) : l); - } - - /* - * @see ILineTracker#getLineOffset - */ - public int getLineOffset(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0) - return 0; - - if (line == lines) { - Line l= (Line) fLines.get(line - 1); - return l.offset + l.length; - } - - Line l= (Line) fLines.get(line); - return l.offset; - } - - /* - * @see ILineTracker#getNumberOfLines - */ - public int getNumberOfLines() { - - int lines= fLines.size(); - - if (lines == 0) - return 1; - - Line l= (Line) fLines.get(lines - 1); - return (l.delimiter != null ? lines + 1 : lines); - } - - /* - * @see ILineTracker#getNumberOfLines(int, int) - */ - public int getNumberOfLines(int position, int length) throws BadLocationException { - - if (position < 0 || position + length > fTextLength) - throw new BadLocationException(); - - if (length == 0) // optimization - return 1; - - return getNumberOfLines(getLineNumberOfOffset(position), position, length); - } - - /* - * @see ILineTracker#computeNumberOfLines(String) - */ - public int computeNumberOfLines(String text) { - int count= 0; - int start= 0; - DelimiterInfo delimiterInfo= nextDelimiterInfo(text, start); - while (delimiterInfo != null && delimiterInfo.delimiterIndex > -1) { - ++count; - start= delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; - delimiterInfo= nextDelimiterInfo(text, start); - } - return count; - } - - - /* ----------------- manipulation ------------------------------ */ - - - /** - * Returns the info of the first delimiter found in the given - * text starting at the given offset. - * - * @param text the text to be searched - * @param offset the offset in the given text - * @return the info of the first found delimiter or <code>null</code> if - * there is no such info - */ - protected abstract DelimiterInfo nextDelimiterInfo(String text, int offset); - - - /** - * Creates the line structure for the given text. Newly created lines - * are inserted into the line structure starting at the given - * position. Returns the number of newly created lines. - * - * @param text the text for which to create a line structure - * @param insertPosition the position at which the newly created lines are inserted - * into the tracker's line structure - * @param offset the offset of all newly created lines - * @return the number of newly created lines - */ - private int createLines(String text, int insertPosition, int offset) { - - int count= 0; - int start= 0; - DelimiterInfo delimiterInfo= nextDelimiterInfo(text, 0); - - - while (delimiterInfo != null && delimiterInfo.delimiterIndex > -1) { - - int index= delimiterInfo.delimiterIndex + (delimiterInfo.delimiterLength - 1); - - if (insertPosition + count >= fLines.size()) - fLines.add(new Line(offset + start, offset + index, delimiterInfo.delimiter)); - else - fLines.add(insertPosition + count, new Line(offset + start, offset + index, delimiterInfo.delimiter)); - - ++count; - start= index + 1; - delimiterInfo= nextDelimiterInfo(text, start); - } - - if (start < text.length()) { - if (insertPosition + count < fLines.size()) { - // there is a line below the current - Line l= (Line) fLines.get(insertPosition + count); - int delta= text.length() - start; - l.offset -= delta; - l.length += delta; - } else { - fLines.add(new Line(offset + start, offset + text.length() - 1, null)); - ++count; - } - } - - return count; - } - - /** - * Keeps track of the line information when text is inserted. - * Returns the number of inserted lines. - * - * @param lineNumber the line at which the insert happens - * @param offset at which the insert happens - * @param text the inserted text - * @return the number of inserted lines - * @exception BadLocationException if offset is invalid in this tracker - */ - private int insert(int lineNumber, int offset, String text) throws BadLocationException { - - if (text == null || text.length() == 0) - return 0; - - fTextLength += text.length(); - - int size= fLines.size(); - - if (size == 0 || lineNumber >= size) - return createLines(text, size, offset); - - Line line= (Line) fLines.get(lineNumber); - DelimiterInfo delimiterInfo= nextDelimiterInfo(text, 0); - if (delimiterInfo == null || delimiterInfo.delimiterIndex == -1) { - line.length += text.length(); - return 0; - } - - - // as there is a line break, split line but do so only if rest of line is not of length 0 - int restLength= line.offset + line.length - offset; - if (restLength > 0) { - // determine start and end of the second half of the splitted line - Line lineRest= new Line(offset, restLength); - lineRest.delimiter= line.delimiter; - // shift it by the inserted text - lineRest.offset += text.length(); - // and insert in line structure - fLines.add(lineNumber + 1, lineRest); - } - - // adapt the beginning of the splitted line - line.delimiter= delimiterInfo.delimiter; - int nextStart= offset + delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; - line.length= nextStart - line.offset; - - // insert lines for the remaining text - text= text.substring(delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength); - return createLines(text, lineNumber + 1, nextStart) + 1; - } - - /** - * Keeps track of the line information when text is removed. Returns - * whether the line at which the deletion start will thereby be deleted. - * - * @param lineNumber the lineNumber at which the deletion starts - * @param offset the offset of the first deleted character - * @param length the number of deleted characters - * @return whethere the start line of the deletion has been deleted - * @exception BadLocationException if position is unkown to the tracker - */ - private boolean remove(int lineNumber, int offset, int length) throws BadLocationException { - - if (length == 0) - return false; - - int removedLineEnds= getNumberOfLines(lineNumber, offset, length) - 1; - Line line= (Line) fLines.get(lineNumber); - - if ((lineNumber == fLines.size() - 1) && removedLineEnds > 0) { - line.length -= length; - line.delimiter= null; - } else { - - ++ lineNumber; - for (int i= 1; i <= removedLineEnds; i++) { - - if (lineNumber == fLines.size()) { - line.delimiter= null; - break; - } - - Line line2= (Line) fLines.get(lineNumber); - line.length += line2.length; - line.delimiter= line2.delimiter; - fLines.remove(lineNumber); - } - line.length -= length; - } - - fTextLength -= length; - - if (line.length == 0) { - fLines.remove(line); - return true; - } - - return false; - } - - /** - * Adapts the offset of all lines with line numbers greater than the specified - * one to the given delta. - * - * @param lineNumber the line number after which to start - * @param delta the offset delta to be applied - */ - private void adaptLineOffsets(int lineNumber, int delta) { - int size= fLines.size(); - for (int i= lineNumber + 1; i < size; i++) { - Line l= (Line) fLines.get(i); - l.offset += delta; - } - } - - /* - * @see ILineTracker#replace - */ - public void replace(int position, int length, String text) throws BadLocationException { - - int lineNumber= getLineNumberOfOffset(position); - int insertLineNumber= lineNumber; - - if (remove(lineNumber, position, length)) - -- lineNumber; - - lineNumber += insert(insertLineNumber, position, text); - - int delta= -length; - if (text != null) - delta= text.length() + delta; - - if (delta != 0) - adaptLineOffsets(lineNumber, delta); - } - - /* - * @see ILineTracker#set - */ - public void set(String text) { - fLines.clear(); - if (text != null) { - fTextLength= text.length(); - createLines(text, 0, 0); - } - } - - /* - * @see ILineTracker#getLineDelimiter - */ - public String getLineDelimiter(int line) throws BadLocationException { - - int lines= fLines.size(); - - if (line < 0 || line > lines) - throw new BadLocationException(); - - if (lines == 0) - return null; - - if (line == lines) - return null; - - Line l= (Line) fLines.get(line); - return l.delimiter; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Assert.java b/org.eclipse.text/src/org/eclipse/jface/text/Assert.java deleted file mode 100644 index 02cfc73a540..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Assert.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * <code>Assert</code> is useful for for embedding runtime sanity checks - * in code. The static predicate methods all test a condition and throw some - * type of unchecked exception if the condition does not hold. - * <p> - * Assertion failure exceptions, like most runtime exceptions, are - * thrown when something is misbehaving. Assertion failures are invariably - * unspecified behavior; consequently, clients should never rely on - * these being thrown (or not thrown). <b>If you find yourself in the - * position where you need to catch an assertion failure, you have most - * certainly written your program incorrectly.</b> - * </p> - * <p> - * Note that an <code>assert</code> statement is slated to be added to the - * Java language in JDK 1.4, rending this class obsolete. - * </p> - */ -public final class Assert { - - /** - * <code>AssertionFailedException</code> is a runtime exception thrown - * by some of the methods in <code>Assert</code>. - * <p> - * This class is not declared public to prevent some misuses; programs that catch - * or otherwise depend on assertion failures are susceptible to unexpected - * breakage when assertions in the code are added or removed. - * </p> - */ - private static class AssertionFailedException extends RuntimeException { - - /** - * Constructs a new exception. - */ - public AssertionFailedException() { - } - - /** - * Constructs a new exception with the given message. - */ - public AssertionFailedException(String detail) { - super(detail); - } - } -/* This class is not intended to be instantiated. */ -private Assert() { -} -/** - * Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * - * @param expression the outcome of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ -public static boolean isLegal(boolean expression) { - // succeed as quickly as possible - if (expression) { - return true; - } - return isLegal(expression, "");//$NON-NLS-1$ -} -/** - * Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcome of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ -public static boolean isLegal(boolean expression, String message) { - if (!expression) - throw new IllegalArgumentException("assertion failed; " + message); //$NON-NLS-1$ - return expression; -} -/** - * Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * <p> - * As a general rule, parameters passed to API methods must not be - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Similarly, results returned from API methods are never - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Implementations are encouraged to make regular use of - * <code>Assert.isNotNull</code> to ensure that <code>null</code> - * parameters are detected as early as possible. - * </p> - * - * @param object the value to test - * @exception Throwable an unspecified unchecked exception if the object - * is <code>null</code> - */ -public static void isNotNull(Object object) { - // succeed as quickly as possible - if (object != null) { - return; - } - isNotNull(object, "");//$NON-NLS-1$ -} -/** - * Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * <p> - * As a general rule, parameters passed to API methods must not be - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Similarly, results returned from API methods are never - * <code>null</code> unless <b>explicitly</b> allowed in the method's - * specification. Implementations are encouraged to make regular use of - * <code>Assert.isNotNull</code> to ensure that <code>null</code> - * parameters are detected as early as possible. - * </p> - * - * @param object the value to test - * @param message the message to include in the exception - * @exception Throwable an unspecified unchecked exception if the object - * is <code>null</code> - */ -public static void isNotNull(Object object, String message) { - if (object == null) - throw new AssertionFailedException("null argument;" + message);//$NON-NLS-1$ -} -/** - * Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param expression the outcome of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ -public static boolean isTrue(boolean expression) { - // succeed as quickly as possible - if (expression) { - return true; - } - return isTrue(expression, "");//$NON-NLS-1$ -} -/** - * Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcome of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ -public static boolean isTrue(boolean expression, String message) { - if (!expression) - throw new AssertionFailedException("Assertion failed: "+message);//$NON-NLS-1$ - return expression; -} -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java b/org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java deleted file mode 100644 index 17f208044f2..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/BadLocationException.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Indicates the attempt to access a non-existing position. - * The attempt has been performed on a text store such as a document or string. - */ -public class BadLocationException extends Exception { - - /** - * Creates a new bad location exception. - */ - public BadLocationException() { - super(); - } - - /** - * Creates a new bad location exception. - * - * @param message the exception message - */ - public BadLocationException(String message) { - super(message); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java b/org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java deleted file mode 100644 index ba853d861bc..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/BadPositionCategoryException.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Indicates the attempt to access a non-existing position - * category in a document. - * - * @see IDocument - */ -public class BadPositionCategoryException extends Exception { - - /** - * Creates a new bad position category exception. - */ - public BadPositionCategoryException() { - super(); - } - - /** - * Creates a new bad position category exception. - * - * @param message the exception's message - */ - public BadPositionCategoryException(String message) { - super(message); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/ChildDocument.java deleted file mode 100644 index 7d2185c3302..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocument.java +++ /dev/null @@ -1,290 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - - -/** - * A child document represent a range of its parent document. - * The child document is always in sync with its parent document - * by utilizing the parent document as its <code>ITextStore</code>. - * This class is for internal use only. - * - * @see ITextStore - */ -public final class ChildDocument extends AbstractDocument { - - - /** - * Implements ITextStore based on IDocument. - */ - class TextStore implements ITextStore { - - /* - * @see ITextStore#set - */ - public void set(String txt) { - try { - fParentDocument.replace(fRange.getOffset(), fRange.getLength(), txt); - } catch (BadLocationException x) { - // cannot happen - } - } - - /* - * @see ITextStore#replace - */ - public void replace(int offset, int length, String txt) { - try { - fParentDocument.replace(fRange.getOffset() + offset, length, txt); - } catch (BadLocationException x) { - // ignored as surrounding document should have handled this - } - } - - /* - * @see ITextStore#getLength - */ - public int getLength() { - return fRange.getLength(); - } - - /* - * @see ITextStore#get - */ - public String get(int offset, int length) { - try { - return fParentDocument.get(fRange.getOffset() + offset, length); - } catch (BadLocationException x) { - } - - return null; - } - - /* - * @see ITextStore#get - */ - public char get(int offset) { - try { - return fParentDocument.getChar(fRange.getOffset() + offset); - } catch (BadLocationException x) { - } - - return (char) 0; - } - }; - - - - /** The parent document */ - private IDocument fParentDocument; - /** - * The parent document as document extension - * @since 2.0 - */ - private IDocumentExtension fExtension; - - /** The section inside the parent document */ - private Position fRange; - /** The document event issued by the parent document */ - private DocumentEvent fParentEvent; - /** The document event issued and to be issued by the child document */ - private DocumentEvent fEvent; - /** Indicates whether the child document initiated a parent document update or not */ - private boolean fIsUpdating= false; - - /** - * Creates a child document for the given range of the given parent document. - * - * @param parentDocument the parent Document - * @param range the parent document range covered by the child document - */ - public ChildDocument(IDocument parentDocument, Position range) { - super(); - - fParentDocument= parentDocument; - if (fParentDocument instanceof IDocumentExtension) - fExtension= (IDocumentExtension) fParentDocument; - - fRange= range; - - ITextStore s= new TextStore(); - ILineTracker tracker= new DefaultLineTracker(); - tracker.set(s.get(0, fRange.getLength())); - - setTextStore(s); - setLineTracker(tracker); - - completeInitialization(); - } - - /** - * Sets the child document's parent document range. - * - * @param offset the offset of the parent document range - * @param length the length of the parent document range - */ - public void setParentDocumentRange(int offset, int length) throws BadLocationException { - - if (offset < 0 || length < 0 || offset + length > fParentDocument.getLength()) - throw new BadLocationException(); - - fRange.setOffset(offset); - fRange.setLength(length); - - getTracker().set(fParentDocument.get(offset, length)); - } - - /** - * Returns parent document - * - * @return the parent document - */ - public IDocument getParentDocument() { - return fParentDocument; - } - - /** - * Returns the range of the parent document covered by this child document. - * - * @return the child document's parent document range - */ - public Position getParentDocumentRange() { - return fRange; - } - - /** - * Transforms a document event of the parent document into a child document - * based document event. - * - * @param e the parent document event - * @return the child document event - */ - private DocumentEvent normalize(DocumentEvent e) { - - int delta= e.getOffset() - fRange.getOffset(); - int offset= delta < 0 ? 0 : delta; - int length= delta < 0 ? e.fLength + delta : e.fLength; - if (offset + length > fRange.getLength()) - length= fRange.getLength() - offset; - - return new ChildDocumentEvent(this, offset, length, e.fText, e); - } - - /** - * When called this child document is informed about a forthcoming change - * of its parent document. This child document checks whether the parent - * document changed affects it and if so informs all document listeners. - * - * @param event the parent document event - */ - public void parentDocumentAboutToBeChanged(DocumentEvent event) { - - fParentEvent= event; - - if (fRange.overlapsWith(event.fOffset, event.fLength)) { - fEvent= normalize(event); - delayedFireDocumentAboutToBeChanged(); - } else - fEvent= null; - } - - /** - * When called this child document is informed about a change of its parent document. - * If this child document is affected it informs all of its document listeners. - * - * @param event the parent document event - */ - public void parentDocumentChanged(DocumentEvent event) { - if ( !fIsUpdating && event == fParentEvent && fEvent != null) { - try { - getTracker().replace(fEvent.fOffset, fEvent.fLength, fEvent.fText); - fireDocumentChanged(fEvent); - } catch (BadLocationException x) { - Assert.isLegal(false); - } - } - } - - /* - * @see AbstractDocument#fireDocumentAboutToBeChanged - */ - protected void fireDocumentAboutToBeChanged(DocumentEvent event) { - // delay it until there is a notification from the parent document - // otherwise there it is expensive to construct the parent document information - } - - /** - * Fires the child document event as about-to-be-changed event to all - * registed listeners. - */ - private void delayedFireDocumentAboutToBeChanged() { - super.fireDocumentAboutToBeChanged(fEvent); - } - - /** - * Ignores the given event and sends the similar child document event instead. - * - * @param event the event to be ignored - */ - protected void fireDocumentChanged(DocumentEvent event) { - super.fireDocumentChanged(fEvent); - } - - /* - * @see IDocument#replace(int, int, String) - * @since 2.0 - */ - public void replace(int offset, int length, String text) throws BadLocationException { - try { - fIsUpdating= true; - if (fExtension != null) - fExtension.stopPostNotificationProcessing(); - - super.replace(offset, length, text); - - } finally { - fIsUpdating= false; - if (fExtension != null) - fExtension.resumePostNotificationProcessing(); - } - } - - /* - * @see IDocument#set(String) - * @since 2.0 - */ - public void set(String text) { - try { - fIsUpdating= true; - if (fExtension != null) - fExtension.stopPostNotificationProcessing(); - - super.set(text); - - } finally { - fIsUpdating= false; - if (fExtension != null) - fExtension.resumePostNotificationProcessing(); - } - } - - /* - * @see IDocumentExtension#registerPostNotificationReplace(IDocumentListener, IDocumentExtension.IReplace) - * @since 2.0 - */ - public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { - if (!fIsUpdating) - throw new UnsupportedOperationException(); - super.registerPostNotificationReplace(owner, replace); - } -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentEvent.java deleted file mode 100644 index cc5e52976b5..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * A child document event represents a parent document event as a - * child-relative document event. It also carries the original event. - */ -public class ChildDocumentEvent extends DocumentEvent { - - /** The parent document event */ - private DocumentEvent fParentEvent; - - /** - * Creates a new child document event. - * - * @param doc the child document - * @param offset the offset in the child document - * @param length the length in the child document - * @param text the substitution text - * @param parentEvent the parent Event - */ - public ChildDocumentEvent(IDocument doc, int offset, int length, String text, DocumentEvent parentEvent) { - super(doc, offset, length, text); - fParentEvent= parentEvent; - } - - /** - * Returns this event's parent event. - * - * @return this event's parent event - */ - public DocumentEvent getParentEvent() { - return fParentEvent; - } -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java b/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java deleted file mode 100644 index 2b9ed9a4b19..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java +++ /dev/null @@ -1,312 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - - -/** - * Manages a set of child documents for given parent documents. - * A child document represents a particular range of the parent - * document and is accordingly adapted to changes of the parent document. - * Vice versa, the parent document is accordingly adapted to changes of - * its child documents. The manager does not maintain any particular management - * structure but utilizes mechanisms given by <code>IDocument</code> such - * as position categories and position updaters. <p> - * - * For internal use only. - */ -public final class ChildDocumentManager implements IDocumentListener { - - - /** - * Name of the position categories used to keep track of the child - * documents offset ranges into the parent document. - */ - public final static String CHILDDOCUMENTS= "__childdocuments"; //$NON-NLS-1$ - - - /** - * Positions which are used to mark the child documents offset ranges into - * the parent documents. This position uses as bidirectional reference as - * it knows the child document as well as the parent document. - */ - static class ChildPosition extends Position { - - public IDocument fParentDocument; - public ChildDocument fChildDocument; - - public ChildPosition(IDocument parentDocument, int offset, int length) { - super(offset, length); - fParentDocument= parentDocument; - } - - /** - * Changed to be compatible to the position updater behavior - * @see Position#overlapsWith(int, int) - */ - public boolean overlapsWith(int offset, int length) { - boolean append= (offset == this.offset + this.length) && length == 0; - return append || super.overlapsWith(offset, length); - } - }; - - - /** - * The position updater used to adapt the positions representing - * the child document ranges to changes of the parent document. - */ - static class ChildPositionUpdater extends DefaultPositionUpdater { - - /** - * Creates the position updated. - */ - protected ChildPositionUpdater() { - super(CHILDDOCUMENTS); - } - - /** - * Child document ranges cannot be deleted other then by calling - * freeChildDocument. - */ - protected boolean notDeleted() { - return true; - } - - /** - * If an insertion happens at a child document's start 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 child document partitioner uses the parent document to answer all questions. - */ - static class ChildPartitioner implements IDocumentPartitioner { - - protected ChildDocument fChildDocument; - protected IDocument fParentDocument; - - protected ChildPartitioner() { - } - - /* - * @see IDocumentPartitioner#getPartition(int) - */ - public ITypedRegion getPartition(int offset) { - try { - offset += fChildDocument.getParentDocumentRange().getOffset(); - return fParentDocument.getPartition(offset); - } catch (BadLocationException x) { - } - - return null; - } - - /* - * @see IDocumentPartitioner#computePartitioning(int, int) - */ - public ITypedRegion[] computePartitioning(int offset, int length) { - try { - offset += fChildDocument.getParentDocumentRange().getOffset(); - return fParentDocument.computePartitioning(offset, length); - } catch (BadLocationException x) { - } - - return null; - } - - /* - * @see IDocumentPartitioner#getContentType(int) - */ - public String getContentType(int offset) { - try { - offset += fChildDocument.getParentDocumentRange().getOffset(); - return fParentDocument.getContentType(offset); - } catch (BadLocationException x) { - } - - return null; - } - - /* - * @see IDocumentPartitioner#getLegalContentTypes() - */ - public String[] getLegalContentTypes() { - return fParentDocument.getLegalContentTypes(); - } - - /* - * @see IDocumentPartitioner#documentChanged(DocumentEvent) - */ - public boolean documentChanged(DocumentEvent event) { - // ignore as the parent does this for us - return false; - } - - /* - * @see IDocumentPartitioner#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - // ignore as the parent does this for us - } - - /* - * @see IDocumentPartitioner#disconnect() - */ - public void disconnect() { - fChildDocument= null; - fParentDocument= null; - } - - /* - * @see IDocumentPartitioner#connect(IDocument) - */ - public void connect(IDocument childDocument) { - Assert.isTrue(childDocument instanceof ChildDocument); - fChildDocument= (ChildDocument) childDocument; - fParentDocument= fChildDocument.getParentDocument(); - } - }; - - - - /** The position updater shared by all documents which have child documents */ - private IPositionUpdater fChildPositionUpdater; - - - - /** - * Returns the child position updater. If necessary, it is dynamically created. - * - * @return the child position updater - */ - protected IPositionUpdater getChildPositionUpdater() { - if (fChildPositionUpdater == null) - fChildPositionUpdater= new ChildPositionUpdater(); - return fChildPositionUpdater; - } - - /** - * Creates and returns a new child document for the specified range of the given parent document. - * The created child document is initialized with a child document partitioner. - * - * @param parent the parent document - * @param offset the offset of the parent document range - * @param length the length of the parent document range - * @exception BadLocationException if the specified range is invalid in the parent document - */ - public ChildDocument createChildDocument(IDocument parent, int offset, int length) throws BadLocationException { - - if (!parent.containsPositionCategory(CHILDDOCUMENTS)) { - parent.addPositionCategory(CHILDDOCUMENTS); - parent.addPositionUpdater(getChildPositionUpdater()); - parent.addDocumentListener(this); - } - - ChildPosition pos= new ChildPosition(parent, offset, length); - try { - parent.addPosition(CHILDDOCUMENTS, pos); - } catch (BadPositionCategoryException x) { - // cannot happen - } - - ChildDocument child= new ChildDocument(parent, pos); - IDocumentPartitioner partitioner= new ChildPartitioner(); - child.setDocumentPartitioner(partitioner); - partitioner.connect(child); - - pos.fChildDocument= child; - - return child; - } - - /** - * Disconnects the given child document from it's parent document and frees - * all resources which are no longer needed. - * - * @param childDocument the child document to be freed - */ - public void freeChildDocument(ChildDocument childDocument) { - - childDocument.getDocumentPartitioner().disconnect(); - - ChildPosition pos= (ChildPosition) childDocument.getParentDocumentRange(); - IDocument parent= pos.fParentDocument; - - try { - parent.removePosition(CHILDDOCUMENTS, pos); - Position[] category= parent.getPositions(CHILDDOCUMENTS); - if (category.length == 0) { - parent.removeDocumentListener(this); - parent.removePositionUpdater(getChildPositionUpdater()); - parent.removePositionCategory(CHILDDOCUMENTS); - } - } catch (BadPositionCategoryException x) { - // cannot happen - } - } - - /** - * Informs all child documents of the document which issued this document event. - * - * @param about indicates whether the change is about to happen or alread happend - * @param event the document event which will be processed to inform child documents - */ - protected void fireDocumentEvent(boolean about, DocumentEvent event) { - try { - - IDocument parent= event.getDocument(); - Position[] children= parent.getPositions(CHILDDOCUMENTS); - for (int i= 0; i < children.length; i++) { - Object o= children[i]; - if (o instanceof ChildPosition) { - ChildPosition pos= (ChildPosition) o; - if (about) - pos.fChildDocument.parentDocumentAboutToBeChanged(event); - else - pos.fChildDocument.parentDocumentChanged(event); - } - } - } catch (BadPositionCategoryException x) { - // cannot happen - } - } - - /* - * @see IDocumentListener#documentChanged(DocumentEvent) - */ - public void documentChanged(DocumentEvent event) { - fireDocumentEvent(false, event); - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - fireDocumentEvent(true, event); - } -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java deleted file mode 100644 index 817bd9cdf29..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ConfigurableLineTracker.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -/** - * Standard implementation of a generic <code>ILineTracker</code>. - * The line tracker can be configured with the set of legal line delimiters. - * Line delimiters are unconstrainted. The line delimiters are used to - * compute the tracker's line structure. In the case of overlapping line delimiters, - * the longest line delimiter is given precedence of the shorter ones.<p> - * This class is not intended to be subclassed. - */ -public class ConfigurableLineTracker extends AbstractLineTracker { - - - /** The strings which are considered being the line delimiter */ - private String[] fDelimiters; - /** A predefined delimiter info which is always reused as return value */ - private DelimiterInfo fDelimiterInfo= new DelimiterInfo(); - - - /** - * Creates a standard line tracker for the given line delimiters. - * - * @param legalLineDelimiters the tracker's legal line delimiters, - * may not be <code>null</code> and must be longer than 0 - */ - public ConfigurableLineTracker(String[] legalLineDelimiters) { - Assert.isTrue(legalLineDelimiters != null && legalLineDelimiters.length > 0); - fDelimiters= legalLineDelimiters; - } - - /* - * @see ILineDelimiter@getLegalLineDelimiters - */ - public String[] getLegalLineDelimiters() { - return fDelimiters; - } - - /* - * @see AbstractLineTracker#nextDelimiterInfo(String, int) - */ - protected DelimiterInfo nextDelimiterInfo(String text, int offset) { - int[] info= TextUtilities.indexOf(fDelimiters, text, offset); - if (info[0] == -1) - return null; - - fDelimiterInfo.delimiterIndex= info[0]; - fDelimiterInfo.delimiter= fDelimiters[info[1]]; - fDelimiterInfo.delimiterLength= fDelimiterInfo.delimiter.length(); - return fDelimiterInfo; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java deleted file mode 100644 index 4f4b0eca98e..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DefaultLineTracker.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -/** - * Standard implementation of <code>ILineTracker</code>. - * The line tracker considers the three common line - * delimiters which are '\n', '\r', '\r\n'.<p> - * This class is not intended to be subclassed. - */ -public class DefaultLineTracker extends AbstractLineTracker { - - /** The predefined delimiters of this tracker */ - public final static String[] DELIMITERS= { "\r", "\n", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$ - /** A predefined delimiter info which is always reused as return value */ - private DelimiterInfo fDelimiterInfo= new DelimiterInfo(); - - - /** - * Creates a standard line tracker. - */ - public DefaultLineTracker() { - } - - /* - * @see ILineDelimiter@getLegalLineDelimiters - */ - public String[] getLegalLineDelimiters() { - return DELIMITERS; - } - - /* - * @see AbstractLineTracker#nextDelimiterInfo(String, int) - */ - protected DelimiterInfo nextDelimiterInfo(String text, int offset) { - - char ch; - int length= text.length(); - for (int i= offset; i < length; i++) { - - ch= text.charAt(i); - if (ch == '\r') { - - if (i + 1 < length) { - if (text.charAt(i + 1) == '\n') { - fDelimiterInfo.delimiter= DELIMITERS[2]; - fDelimiterInfo.delimiterIndex= i; - fDelimiterInfo.delimiterLength= 2; - return fDelimiterInfo; - } - } - - fDelimiterInfo.delimiter= DELIMITERS[0]; - fDelimiterInfo.delimiterIndex= i; - fDelimiterInfo.delimiterLength= 1; - return fDelimiterInfo; - - } else if (ch == '\n') { - - fDelimiterInfo.delimiter= DELIMITERS[1]; - fDelimiterInfo.delimiterIndex= i; - fDelimiterInfo.delimiterLength= 1; - return fDelimiterInfo; - } - } - - return null; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java b/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java deleted file mode 100644 index c5044eb3f5e..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DefaultPositionUpdater.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Default implementation of <code>IPositionUpdater</code>. - * A default position updater must be configured with the position category - * whose positions it will update. Other position categories are not affected - * by this updater.<p> - * This implementation follows the following specification: - * <ul> - * <li> Inserting or deleting text before the position shifts the position accordingly. - * <li> Inserting text at the position offset shifts the position accordingly. - * <li> Inserting or deleting text completely surrounded by the position shrinks or stretches the position. - * <li> Inserting or deleting text after a position does not affect the position. - * <li> Deleting text which completly contains the position deletes the position. - * <li> Replacing text overlapping with the position considered as a sequence of first - * deleting the replaced text and afterwards inserting the new text. Thus, a - * position might first be shifted and shrink and then be stretched. - * </ul> - * This class can be used as is or be adapted by subclasses. Fields are protected to - * allow subclasses direct access. Because of the frequency with which position updaters - * are used this is a performance decision. - */ -public class DefaultPositionUpdater implements IPositionUpdater { - - /** The position category the updater draws responsible for */ - private String fCategory; - - /** Caches the currently investigated position */ - protected Position fPosition; - /** Remembers the original state of the investigated position */ - protected Position fOriginalPosition= new Position(0, 0); - /** Caches the offset of the replaced text */ - protected int fOffset; - /** Caches the length of the replaced text */ - protected int fLength; - /** Caches the length of the newly inserted text */ - protected int fReplaceLength; - /** Catches the document */ - protected IDocument fDocument; - - - /** - * Creates a new default positon updater for the given category. - * - * @param category the category the updater is responsible for - */ - public DefaultPositionUpdater(String category) { - fCategory= category; - } - - /** - * Returns the category this updater is resonsible for. - * - * @return the category this updater is resonsible for - */ - protected String getCategory() { - return fCategory; - } - - /** - * Adapts the currently investigated position to an insertion. - */ - 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 (fLength <= 0) { - - if (myStart < yoursStart) - fPosition.length += fReplaceLength; - else - fPosition.offset += fReplaceLength; - - } else { - - if (myStart <= yoursStart && fOriginalPosition.offset <= yoursStart) - fPosition.length += fReplaceLength; - else - fPosition.offset += fReplaceLength; - } - } - - /** - * Adapts the currently investigated position to a deletion. - */ - protected void adaptToRemove() { - - int myStart= fPosition.offset; - int myEnd= fPosition.offset + fPosition.length -1; - myEnd= Math.max(myStart, myEnd); - - int yoursStart= fOffset; - int yoursEnd= fOffset + fLength -1; - yoursEnd= Math.max(yoursStart, yoursEnd); - - if (myEnd < yoursStart) - return; - - if (myStart <= yoursStart) { - - if (yoursEnd <= myEnd) - fPosition.length -= fLength; - else - fPosition.length -= (myEnd - yoursStart +1); - - } else if (yoursStart < myStart) { - - if (yoursEnd < myStart) - fPosition.offset -= fLength; - else { - fPosition.offset -= (myStart - yoursStart); - fPosition.length -= (yoursEnd - myStart +1); - } - - } - - // validate position to allowed values - if (fPosition.offset < 0) - fPosition.offset= 0; - - if (fPosition.length < 0) - fPosition.length= 0; - } - - /** - * Adapts the currently investigated position to the replace operation. - * First it checks whether the change replaces the whole range of the position. - * If not, it performs first the deletion of the previous text and afterwards - * the insertion of the new text. - */ - protected void adaptToReplace() { - - if (fPosition.offset == fOffset && fPosition.length == fLength && fPosition.length > 0) { - - // replace the whole range of the position - fPosition.length += (fReplaceLength - fLength); - if (fPosition.length < 0) { - fPosition.offset += fPosition.length; - fPosition.length= 0; - } - - } else { - - if (fLength > 0) - adaptToRemove(); - - if (fReplaceLength > 0) - adaptToInsert(); - } - } - - /** - * Determines whether the currently investigated position has been deleted by - * the replace operation specified in the current event. If so, it deletes - * the position and removes it from the document's position category. - * - * @return <code>true</code> if position has been deleted - */ - protected boolean notDeleted() { - - if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) { - - fPosition.delete(); - - try { - fDocument.removePosition(fCategory, fPosition); - } catch (BadPositionCategoryException x) { - } - - return false; - } - - return true; - } - - /* - * @see IPositionUpdater#update(DocumentEvent event) - */ - public void update(DocumentEvent event) { - - try { - - Position[] category= event.getDocument().getPositions(fCategory); - - fOffset= event.getOffset(); - fLength= event.getLength(); - fReplaceLength= (event.getText() == null ? 0 : event.getText().length()); - fDocument= event.getDocument(); - - for (int i= 0; i < category.length; i++) { - - fPosition= category[i]; - fOriginalPosition.offset= fPosition.offset; - fOriginalPosition.length= fPosition.length; - - if (notDeleted()) - adaptToReplace(); - } - - } catch (BadPositionCategoryException x) { - // do nothing - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Document.java b/org.eclipse.text/src/org/eclipse/jface/text/Document.java deleted file mode 100644 index 688e328325c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Document.java +++ /dev/null @@ -1,71 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Default document implementation. Uses a gap text store as text store and - * installs a line tracker considering the following strings as line delimiters - * "\n", "\r", "\r\n". The document is ready to use. It has a default position - * category for which a default position updater is installed. - * - * @see GapTextStore - */ -public class Document extends AbstractDocument { - - - /** - * Creates a new empty document. - */ - public Document() { - super(); - setTextStore(new GapTextStore(50, 300)); - setLineTracker(new DefaultLineTracker()); - completeInitialization(); - } - - /** - * Creates a new document with the given initial content. - * - * @param initialContent the document's initial content - */ - public Document(String initialContent) { - super(); - setTextStore(new GapTextStore(50, 300)); - setLineTracker(new DefaultLineTracker()); - getStore().set(initialContent); - getTracker().set(initialContent); - completeInitialization(); - } - - /* - * @see IDocumentExtension#startSequentialRewrite(boolean) - * @since 2.0 - */ - public void startSequentialRewrite(boolean normalized) { - ITextStore store= new SequentialRewriteTextStore(getStore()); - setTextStore(store); - } - - /* - * @see IDocumentExtension#stopSequentialRewrite() - * @since 2.0 - */ - public void stopSequentialRewrite() { - if (getStore() instanceof SequentialRewriteTextStore) { - SequentialRewriteTextStore srws= (SequentialRewriteTextStore) getStore(); - ITextStore source= srws.getSourceStore(); - setTextStore(source); - srws.dispose(); - } - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java deleted file mode 100644 index ea9aa55185c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/DocumentEvent.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -/** - * Specification of changes applied to documents. - * All changes are represented as replace commands, i.e. - * specifying a document range whose text gets replaced with different text. - * In addition to this information, the event also contains the changed document. - * - * @see IDocument - */ -public class DocumentEvent { - - /** The changed document */ - public IDocument fDocument; - /** The document offset */ - public int fOffset; - /** Length of the replaced document text */ - public int fLength; - /** Text inserted into the document */ - public String fText; - - /** - * Creates a new document event. - * - * @param doc the changed document - * @param offset the offset of the replaced text - * @param length the length of the replaced text - * @param text the substitution text - */ - public DocumentEvent(IDocument doc, int offset, int length, String text) { - - Assert.isNotNull(doc); - Assert.isTrue(offset >= 0); - Assert.isTrue(length >= 0); - - fDocument= doc; - fOffset= offset; - fLength= length; - fText= text; - } - - /** - * Returns the changed document. - * - * @return the changed document - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * Returns the offset of the change - * - * @return the offset of the change - */ - public int getOffset() { - return fOffset; - } - - /** - * Returns the length of the replaced text. - * - * @return the length of the replaced text - */ - public int getLength() { - return fLength; - } - - /** - * Returns the text that has been inserted. - * - * @return the text that has been inserted - */ - public String getText() { - return fText; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java deleted file mode 100644 index 6a8d8827ce5..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/GapTextStore.java +++ /dev/null @@ -1,253 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -/** - * Implements a gap managing text store. The gap text store - * relies on the assumption that subsequent changes of a document are co-located. - * The start of the gap is always moved to the location of the last change. The - * size of the gap varies between the low water mark and the high water mark. <p> - * This class is not intended to be subclassed. - */ -public class GapTextStore implements ITextStore { - - /** The store's content */ - private char[] fContent= new char[0]; - /** Starting index of the gap */ - private int fGapStart= -1; - /** End index of the gap */ - private int fGapEnd= -1; - - /** The high water mark. If the gap is larger than this, it will be shrunken */ - private int fHighWatermark; - /** The low water mark, If this gap is smaller than this, it will be extended */ - private int fLowWatermark; - - /** - * Creates a new empty text store using the specified low and high watermarks. - * - * @param lowWatermark if this gap is ever smaller than this, it will automatically be extended - * @param highWatermark if the gap is ever larger than this, it will automatically be shrunken - */ - public GapTextStore(int lowWatermark, int highWatermark) { - Assert.isTrue(lowWatermark < highWatermark); - fLowWatermark= lowWatermark; - fHighWatermark= highWatermark; - } - - /** - * Adjusts the gap so that is at the right offset and capable of handling - * the addition of a specified number of characters without having to be shifted. - * The <code>sizeHint</code> represents the range that will be filled afterwards. - * If the gap is already at the right offset, it must only be - * resized if it will be no longer between the low and high watermark. However, - * on delete (sizeHint < 0) at the edges of the gap, the gap is only enlarged. - * - * @param offset the offset at which the change happens - * @param sizeHint the number of character which will be inserted - */ - private void adjustGap(int offset, int sizeHint) { - - if (offset == fGapStart) { - int size= (fGapEnd - fGapStart) - sizeHint; - if (fLowWatermark <= size && size <= fHighWatermark) - return; - } - - moveAndResizeGap(offset, sizeHint); - } - - /** - * Moves the gap to the specified offset and adjust its size to the - * anticipated change size. The given size represents the expected - * range of the gap that will be filled after the gap has been moved. - * Thus the gap is resized to actual size + the specified size and - * moved to the given offset. - * - * @param offset the offset where the gap is moved to - * @param size the anticipated size of the change - */ - private void moveAndResizeGap(int offset, int size) { - - char[] content= null; - int oldSize= fGapEnd - fGapStart; - int newSize= fHighWatermark + size; - - - if (newSize < 0) { - - if (oldSize > 0) { - content= new char[fContent.length - oldSize]; - System.arraycopy(fContent, 0, content, 0, fGapStart); - System.arraycopy(fContent, fGapEnd, content, fGapStart, content.length - fGapStart); - fContent= content; - } - fGapStart= fGapEnd= offset; - return; - } - - - content= new char[fContent.length + (newSize - oldSize)]; - - int newGapStart= offset; - int newGapEnd= newGapStart + newSize; - - if (oldSize == 0) { - - System.arraycopy(fContent, 0, content, 0, newGapStart); - System.arraycopy(fContent, newGapStart, content, newGapEnd, content.length - newGapEnd); - - } else if (newGapStart < fGapStart) { - - int delta= fGapStart - newGapStart; - System.arraycopy(fContent, 0, content, 0, newGapStart); - System.arraycopy(fContent, newGapStart, content, newGapEnd, delta); - System.arraycopy(fContent, fGapEnd, content, newGapEnd + delta, fContent.length - fGapEnd); - - } else { - - int delta= newGapStart - fGapStart; - System.arraycopy(fContent, 0, content, 0, fGapStart); - System.arraycopy(fContent, fGapEnd, content, fGapStart, delta); - System.arraycopy(fContent, fGapEnd + delta, content, newGapEnd, content.length - newGapEnd); - } - - - fContent= content; - fGapStart= newGapStart; - fGapEnd= newGapEnd; - } - - /* - * @see ITextStore#get - */ - public char get(int offset) { - - if (offset < fGapStart) - return fContent[offset]; - - int gapLength= fGapEnd - fGapStart; - return fContent[offset + gapLength]; - } - - /* - * @see ITextStore#get - */ - public String get(int offset, int length) { - - int end= offset + length; - - if (fContent == null) - return ""; //$NON-NLS-1$ - - if (end <= fGapStart) - return new String(fContent, offset, length); - - if (fGapStart < offset) { - int gapLength= fGapEnd - fGapStart; - return new String(fContent, offset + gapLength , length); - } - - StringBuffer buf= new StringBuffer(); - buf.append(fContent, offset, fGapStart - offset); - buf.append(fContent, fGapEnd, end - fGapStart); - return buf.toString(); - } - - /* - * @see ITextStore#getLength - */ - public int getLength() { - int length= fGapEnd - fGapStart; - return (fContent.length - length); - } - - - /* - * @see ITextStore#replace - */ - public void replace(int offset, int length, String text) { - - int textLength= (text == null ? 0 : text.length()); - - // handle delete at the edges of the gap - if (textLength == 0) { - if (offset <= fGapStart && offset + length >= fGapStart && fGapStart > -1 && fGapEnd > -1) { - length -= fGapStart - offset; - fGapStart= offset; - fGapEnd += length; - return; - } - } - - // move gap - adjustGap(offset + length, textLength - length); - - // overwrite - int min= Math.min(textLength, length); - for (int i= offset, j= 0; i < offset + min; i++, j++) - fContent[i]= text.charAt(j); - - if (length > textLength) { - // enlarge the gap - fGapStart -= (length - textLength); - } else if (textLength > length) { - // shrink gap - fGapStart += (textLength - length); - for (int i= length; i < textLength; i++) - fContent[offset + i]= text.charAt(i); - } - } - - /** - * Sets the content to <code>text</code> and removes the gap - * since there are no sensible predictions about - * where the next change will occur. - * @see ITextStore#set - */ - public void set(String text) { - - if (text == null) - text= ""; //$NON-NLS-1$ - - fContent= text.toCharArray(); - - fGapStart= -1; - fGapEnd= -1; - } - - /** - * Returns a copy of the content of this text store. - * For internal use only. - * - * @return a copy of the content of this text store - */ - protected String getContentAsString() { - return new String(fContent); - } - - /** - * Returns the start index of the gap managed by this text store. - * For internal use only. - * - * @return the start index of the gap managed by this text store - */ - protected int getGapStartIndex() { - return fGapStart; - } - - /** - * Returns the end index of the gap managed by this text store. - * For internal use only. - * - * @return the end index of the gap managed by this text store - */ - protected int getGapEndIndex() { - return fGapEnd; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocument.java deleted file mode 100644 index 04c6b982233..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocument.java +++ /dev/null @@ -1,570 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -/** - * An <code>IDocument</code> represents text providing support for - * <ul> - * <li> text manipulation - * <li> positions - * <li> partitions - * <li> line information - * <li> search - * <li> document change listeners - * <li> document partition change listeners - * </ul> - * - * A document allows to set its content and to manipulate it. For manipulation - * a document provides the <code>replace</code> method which substitutes a given - * string for a specified text range in the document. On each document change, all - * registered document listeners are informed exactly once. - * - * Positions are stickers to the document's text that are updated when the - * document is changed. Positions are updated by <code>IPositionUpdater</code>s. Position - * updaters are managed as a list. The list defines the sequence in which position - * updaters are invoked.This way, position updaters may rely on each other. - * Positions are grouped into categories. A category is a ordered list of positions. - * the document defines the order of position in a category based on the position's offset - * based on the implementation of the method <code>computeIndexInCategory</code>. - * Each document must support a default position category whose name is specified by this - * interface.<p> - * - * A document can be considered consisting of a sequence of not overlapping partitions. - * A partition is defined by its offset, its length, and its type. Partitions are - * updated on every document manipulation and ensured to be up-to-date when the document - * listeners are informed. A document uses an <code>IDocumentPartitioner</code> to - * manage its partitions. A document may be unpartitioned which happens when there is no - * partitioner. In this case, the document is considered as one singloe partition of a - * default type. The default type is specified by this interface. If a document change - * changes the document's partitioning all registered partitioning listeners are - * informed exactly once.<p> - * - * An <code>IDocument</code> uses an <code>ILineTracker</code> to map line numbers and character - * positions onto each other based on the document's line delimiters. When moving text - * between documents using different line delimiters, the text must be converted to - * use the target document's line delimiters. <p> - * - * <code>IDocument</code> throws <code>BadLocationException</code> if the parameters of - * queries or manipulation requests are not inside the bounds of the document. The purpose - * of this style of exception handling is - * <ul> - * <li> prepare document for multi-thread access - * <li> allow clients to implement backtracking recovery methods - * <li> prevent clients from upfront contract checking when dealing with documents. - * </ul> - * Clients may implement this interface or use the default implementation provided - * by <code>AbstractDocument</code> and <code>Document</code>. - * - * @see Position - * @see IPositionUpdater - * @see IDocumentPartitioner - * @see ILineTracker - * @see IDocumentListener - * @see IDocumentPartitioningListener - */ -public interface IDocument { - - - /** - * The identifier of the default position category. - */ - final static String DEFAULT_CATEGORY= "__dflt_position_category"; //$NON-NLS-1$ - - /** - * The identifier of the default partition content type. - */ - final static String DEFAULT_CONTENT_TYPE= "__dftl_partition_content_type"; //$NON-NLS-1$ - - - - - /* --------------- text access and manipulation --------------------------- */ - - /** - * Returns the character at the given document offset in this document. - * - * @param offset a document offset - * @return the character at the offset - * @exception BadLocationException if the offset is invalid in this document - */ - char getChar(int offset) throws BadLocationException; - - /** - * Returns the number of characters in this document. - * - * @return the number of characters in this document - */ - int getLength(); - - /** - * Returns this document's complete text. - * - * @return the document's complete text - */ - String get(); - - /** - * Returns this document's text for the specified range. - * - * @param offset the document offset - * @param length the length of the specified range - * @return the document's text for the specified range - * @exception BadLocationException if the range is invalid in this document - */ - String get(int offset, int length) throws BadLocationException; - - /** - * Replaces the content of the document with the given text. - * Sends a <code>DocumentEvent</code> to all registered <code>IDocumentListener</code>. - * This method is a convenience method for <code> - * replace(0, getLength(), text)</code>. - * - * @param text the new content of the document - * - * @see DocumentEvent - * @see IDocumentListener - */ - void set(String text); - - /** - * Subsitutes the given text for the specified document range. - * Sends a <code>DocumentEvent</code> to all registered <code>IDocumentListener</code>. - * - * @param offset the document offset - * @param length the length of the specified range - * @param text the substitution text - * @exception BadLocationException if the offset is invalid in this document - * - * @see DocumentEvent - * @see IDocumentListener - */ - void replace(int offset, int length, String text) throws BadLocationException; - - /** - * Registers the document listener with the document. After registration - * the IDocumentListener is informed about each change of this document. - * If the listener is already registered nothing happens.<p> - * An <code>IDocumentListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be registered - */ - void addDocumentListener(IDocumentListener listener); - - /** - * Removes the listener from the document's list of document listeners. - * If the listener is not registered with the document nothing happens.<p> - * An <code>IDocumentListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be removed - */ - void removeDocumentListener(IDocumentListener listener); - - /** - * Adds the given document listener as one which is notified before - * those document listeners added with <code>addDocumentListener</code> - * are notified. If the given listener is also registered using - * <code>addDocumentListener</code> it will be notified twice. - * If the listener is already registered nothing happens.<p> - * - * This method is not for public use, it may only be called by - * implementers of <code>IDocumentAdapter</code> and only if those - * implementers need to implement <code>IDocumentListener</code>. - * - * @param documentAdapter the listener to be added as prenotified document listener - */ - void addPrenotifiedDocumentListener(IDocumentListener documentAdapter); - - /** - * Removes the given document listener from the document's list of - * prenotified document listeners. If the listener is not registered - * with the document nothing happens. <p> - * - * This method is not for public use, it may only be called by - * implementers of <code>IDocumentAdapter</code> and only if those - * implementers need to implement <code>IDocumentListener</code>. - * - * @param documentAdapter the listener to be removed - * - * @see #addPrenotifiedDocumentListener(IDocumentListener) - */ - void removePrenotifiedDocumentListener(IDocumentListener documentAdapter); - - - - /* -------------------------- positions ----------------------------------- */ - - /** - * Adds a new position category to the document. If the position category - * already exists nothing happens. - * - * @param category the category to be added - */ - void addPositionCategory(String category); - - /** - * Deletes the position category from the document. All positions - * in this category are thus deleted as well. - * - * @param category the category to be removed - * @exception BadPositionCategoryException if category is undefined in this document - */ - void removePositionCategory(String category) throws BadPositionCategoryException; - - /** - * Returns all position categories of this document. This - * includes the default position category. - * - * @return the document's position categories - */ - String[] getPositionCategories(); - - /** - * Checks the presence of the specified position category. - * - * @param category the category to check - * @return <code>true</code> if category is defined - */ - boolean containsPositionCategory(String category); - - /** - * Adds the position to the document's default position category. - * This is a convenience method for <code>addPosition(DEFAULT_CATEGORY, position)</code>. - * - * @param position the position to be added - * @exception BadLocationException if position describes an invalid range in this document - */ - void addPosition(Position position) throws BadLocationException; - - /** - * Removes the given position from the document's default position category. - * This is a convenience method for <code>removePosition(DEFAULT_CATEGORY, position)</code>. - * - * @param position the position to be removed - */ - void removePosition(Position position); - - /** - * Adds the position to the specified position category of the document. - * A position that has been added to a position category is updated on each - * change applied to the document. Positions may be added multiple times. - * The order of the category is maintained. - * - * @param category the category to which to add - * @param position the position to be added - * @exception BadLocationException if position describes an invalid range in this document - * @exception BadPositionCategoryException if the category is undefined in this document - */ - void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException; - - /** - * Removes the given position from the specified position category. - * If the position is not part of the specified category nothing happens. - * If the position has been added multiple times, only the first occurence is deleted. - * - * @param category the category from which to delete - * @param position the position to be deleted - * @exception BadPositionCategoryException if category is undefined in this document - */ - void removePosition(String category, Position position) throws BadPositionCategoryException; - - /** - * Returns all positions of the given position category. - * The positions are ordered according to the category's order. - * Manipulating this list does not affect the document, but manipulating the - * position does affect the document. - * - * @param category the category - * @return the list of all positions - * @exception BadPositionCategoryException if category is undefined in this document - */ - Position[] getPositions(String category) throws BadPositionCategoryException; - - /** - * Determines whether a position described by the parameters is managed by this document. - * - * @param category the category to check - * @param offset the offset of the position to find - * @param length the length of the position to find - * @return <code>true</code> if position is found - */ - boolean containsPosition(String category, int offset, int length); - - /** - * Computes the index at which a <code>Position</code> with the - * specified offset would be inserted into the given category. As the - * ordering inside a category only depends on the offset, the index must be - * choosen to be the first of all positions with the same offset. - * - * @param category the category in which would be added - * @param offset the position offset to be considered - * @return the index into the category - * @exception BadLocationException if offset is invalid in this document - * @exception BadPositionCategoryException if category is undefined in this document - */ - int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException; - - /** - * Appends a new position updater to the document's list of position updaters. - * Position updaters may be added multiple times.<p> - * An <code>IPositionUpdater</code> may call back to this method - * when being inside a document notification. - * - * @param updater the updater to be added - */ - void addPositionUpdater(IPositionUpdater updater); - - /** - * Removes the position updater from the document's list of position updaters. - * If the position updater has multiple occurences only the first occurence is - * removed. If the position updater is not registered with this document, nothing - * happens.<p> - * An <code>IPositionUpdater</code> may call back to this method - * when being inside a document notification. - * - * @param updater the updater to be removed - */ - void removePositionUpdater(IPositionUpdater updater); - - /** - * Inserts the position updater at the specified index in the document's - * list of position updaters. Positions updaters may be inserted multiple times.<p> - * An <code>IPositionUpdater</code> may call back to this method - * when being inside a document notification. - * - * @param updater the updater to be inserted - * @param index the index in the document's updater list - */ - void insertPositionUpdater(IPositionUpdater updater, int index); - - /** - * Returns the list of position updaters attached to the document. - * - * @return the list of position updaters - */ - IPositionUpdater[] getPositionUpdaters(); - - - - - /* -------------------------- partitions ---------------------------------- */ - - /** - * Returns the set of legal content types of document partitions. - * This set can be empty. The set can contain more content types than - * contained by the result of <code>getPartitioning(0, getLength())</code>. - * - * @return the set of legal content types - */ - String[] getLegalContentTypes(); - - /** - * Returns the type of the document partition containing the given offset. - * This is a convenience method for <code>getPartition(offset).getType()</code>. - * - * @param offset the document offset - * @return the partition type - * @exception BadLocationException if offset is invalid in this document - */ - String getContentType(int offset) throws BadLocationException; - - /** - * Returns the document partition in which the position is located. - * - * @param offset the document offset - * @return a specification of the partition - * @exception BadLocationException if offset is invalid in this document - */ - ITypedRegion getPartition(int offset) throws BadLocationException; - - /** - * Computes the partitioning of the given document range using the - * document's partitioner. - * - * @param offset the document offset at which the range starts - * @param length the length of the document range - * @return a specification of the range's partitioning - * @exception BadLocationException if the range is invalid in this document - */ - ITypedRegion[] computePartitioning(int offset, int length) throws BadLocationException; - - /** - * Registers the document partitioning listener with the document. After registration - * the document partitioning listener is informed about each partition change - * cause by a document manipulation or by changing the document's partitioner. - * If a document partitioning listener is also - * a document listener, the following notification sequence is guaranteed if a - * document manipulation changes the document partitioning: - * <ul> - * <li>listener.documentAboutToBeChanged(DocumentEvent); - * <li>listener.documentPartitioningChanged(); - * <li>listener.documentChanged(DocumentEvent); - * </ul> - * If the listener is already registered nothing happens.<p> - * An <code>IDocumentPartitioningListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be added - */ - void addDocumentPartitioningListener(IDocumentPartitioningListener listener); - - /** - * Removes the listener from this document's list of document partitioning - * listeners. If the listener is not registered with the document nothing - * happens.<p> - * An <code>IDocumentPartitioningListener</code> may call back to this method - * when being inside a document notification. - * - * @param listener the listener to be removed - */ - void removeDocumentPartitioningListener(IDocumentPartitioningListener listener); - - /** - * Sets this document's partitioner. The caller of this method is responsible for - * disconnecting the document's old partitioner from the document and to - * connect the new partitioner to the document. Informs all document partitioning - * listeners about this change. - * - * @param the document's new partitioner - * - * @see IDocumentPartitioningListener - */ - void setDocumentPartitioner(IDocumentPartitioner partitioner); - - /** - * Returns this document's partitioner. - * - * @return this document's partitioner - */ - IDocumentPartitioner getDocumentPartitioner(); - - - - /* ---------------------- line information -------------------------------- */ - - /** - * Returns the length of the given line including the line's delimiter. - * - * @param line the line of interest - * @return the length of the line - * @exception BadLocationException if the line number is invalid in this document - */ - int getLineLength(int line) throws BadLocationException; - - /** - * Returns the number of the line at which the character of the specified position is located. - * The first line has the line number 0. A new line starts directly after a line - * delimiter. <code>(pos == document length)</code> is a valid argument also there is no - * corresponding character. - * - * @param offset the document offset - * @return the number of the line - * @exception BadLocationException if the offset is invalid in this document - */ - int getLineOfOffset(int offset) throws BadLocationException; - - /** - * Determines the offset of the first character of the given line. - * - * @param line the line of interest - * @return the document offset - * @exception BadLocationException if the line number is invalid in this document - */ - int getLineOffset(int line) throws BadLocationException; - - /** - * Returns a description of the specified line. The line is described by its - * offset and its length excluding the line's delimiter. - * - * @param line the line of interest - * @return a line description - * @exception BadLocationException if the line number is invalid in this document - */ - IRegion getLineInformation(int line) throws BadLocationException; - - /** - * Returns a description of the line at the given offset. - * The description contains the offset and the length of the line - * excluding the line's delimiter. - * - * @param offset the offset whose line should be described - * @return a region describing the line - * @exception BadLocationException if offset is invalid in this document - */ - IRegion getLineInformationOfOffset(int offset) throws BadLocationException; - - /** - * Returns the number of lines in this document - * - * @return the number of lines in this document - */ - int getNumberOfLines(); - - /** - * Returns the number of lines which are occupied by a given text range. - * - * @param offset the offset of the specified text range - * @param length the length of the specified text range - * @return the number of lines occupied by the specified range - * @exception BadLocationException if specified range is invalid in this tracker - */ - int getNumberOfLines(int offset, int length) throws BadLocationException; - - /** - * Computes the number of lines in the given text. For a given - * implementer of this interface this method returns the same - * result as <code>set(text); getNumberOfLines()</code>. - * - * @param text the text whose number of lines should be computed - * @return the number of lines in the given text - */ - int computeNumberOfLines(String text); - - - /* ------------------ line delimiter conversion --------------------------- */ - - /** - * Returns the document's legal line delimiters. - * - * @return the document's legal line delimiters - */ - String[] getLegalLineDelimiters(); - - /** - * Returns the line delimiter of that line. - * - * @param line the line of interest - * @return the line delimiter of that line - * @exception BadLocationException if the line number is invalid in this document - */ - String getLineDelimiter(int line) throws BadLocationException; - - - - /* ---------------------------- search ------------------------------------ */ - - /** - * Returns the offset of a given search string in the document based on a set of search criteria. - * - * @param startOffset document offset at which search starts - * @param findString the string to find - * @param forwardSearch the search direction - * @param caseSensitive indicates whether lower and upper case should be distinguished - * @param wholeWord indicates whether the findString should be limited by white spaces as - * defined by Character.isWhiteSpace - * @return the offset of the first occurence of findString based on the parameters - * @exception BadLocationException if startOffset is an invalid document offset - */ - int search(int startOffset, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException; -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java deleted file mode 100644 index 2986e184bf4..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension.java +++ /dev/null @@ -1,81 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - -/** - * Extension interface for <code>IDocument</code>. <p> - * It introduces the notion of sequentially rewriting a document. This is to tell a - * document that a sequence of non-overlapping replace operation is about to be - * performed.<p> - * Is also introduces the concept of post notification replaces. This is, a document - * listener who is informed about a document change can cause a derived document - * change. As the listener is not allowed to directly modify the document, it can - * register a replace operation that is performed directly after all document listeners - * have been notified. - * - * @since 2.0 - */ -public interface IDocumentExtension { - - /** - * Interface for a post notification replace operation. - */ - public interface IReplace { - - /** - * Executes the replace operation on the given document. - * @param document the document to be changed - * @param owner the owner of this replace operation - */ - void perform(IDocument document, IDocumentListener owner); - }; - - /** - * Callback for document listeners to be used inside <code>documentChanged</code> - * to register a post notification replace operation on the document notifying them. - * - * @param owner the owner of the replace operation - * @param the replace operation to be executed - * @exception UnsupportedOperationException if <code>registerPostNotificationReplace</code> - * is not supported by this document - */ - void registerPostNotificationReplace(IDocumentListener owner, IReplace replace) throws UnsupportedOperationException; - - /** - * Stops the processing of registered post notification replace operations until - * <code>resumePostNotificationProcessing</code> is called. - */ - void stopPostNotificationProcessing(); - - /** - * Resumes the processing of post notification replace operations. If the queue of registered - * <code>IDocumentExtension.IReplace</code> objects is not empty, they are immediately processed if the - * document is not inside a replace operation. If the document is inside a replace operation, - * they are processed directly after the replace operation has finished. - */ - void resumePostNotificationProcessing(); - - /** - * Tells the document that it is about to be sequentially rewritten. That is a - * sequence of non-overlapping replace operations will be performed on it. The - * <code>normalize</code> flag indicates whether the rewrite is preformed from - * the start of the document to its end or from an arbitrary start offset. - * - * @param normalize <code>true</code> if performed from the start to the end of the document - */ - void startSequentialRewrite(boolean normalize); - - /** - * Tells the document that the sequential rewrite has been finished. - */ - void stopSequentialRewrite(); -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java deleted file mode 100644 index dc957f81fb4..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentListener.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Interface for objects which are interested in getting informed about - * document changes. A listener is informed about document changes before - * they are applied and after they have been applied. It is ensured that - * the document event passed into the listener is the same for the two - * notifications, i.e. the two document events can be checked using object identity. - * Clients may implement this interface. - */ -public interface IDocumentListener { - - - /** - * The manipulation described by the document event will be performed. - * - * @param event the document event describing the document change - */ - void documentAboutToBeChanged(DocumentEvent event); - - /** - * The manipulation described by the document event has been performed. - * - * @param event the document event describing the document change - */ - void documentChanged(DocumentEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java deleted file mode 100644 index d1cff732d2c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioner.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * A document partitioner divides a document into a set - * of disjoint text partitions. Each partition has a content type, an - * offset, and a length. The document partitioner is connected to one document - * and informed about all changes of this document before any of the - * document's document listeners. A document partitioner can thus - * incrementally update on the receipt of a document change event. - * Clients may implement this interface or use the standard - * implementation <code>RuleBasedDocumentPartitioner</code>. - * - * @see IDocument - */ -public interface IDocumentPartitioner { - - /** - * Connects the partitioner to a document. - * Connect indicates the begin of the usage of the receiver - * as partitioner of the given document. Thus, resources the partitioner - * needs to be operational for this document should be allocated.<p> - * The caller of this method must ensure that this partitioner is - * also set as the document's document partitioner. - * - * @param document the document to be connected to - */ - void connect(IDocument document); - - /** - * Disconnects the partitioner from the document it is connected to. - * Disconnect indicates the end of the usage of the receiver as - * partitioner of the connected document. Thus, resources the partitioner - * needed to be operation for its connected document should be deallocated.<p> - * The caller of this method should also must ensure that this partitioner is - * no longer the document's partitioner. - */ - void disconnect(); - - /** - * Informs about a forthcoming document change. Will be called by the - * connected document and is not intended to be used by clients - * other than the connected document. - * - * @param event the event describing the forthcoming change - */ - void documentAboutToBeChanged(DocumentEvent event); - - /** - * The document has been changed. The partitioner updates - * the document's partitioning and returns whether the structure of the - * document partitioning has been changed, i.e. whether partitions - * have been added or removed. Will be called by the connected document and - * is not intended to be used by clients other than the connected document. - * - * @param event the event describing the document change - * @return <code>true</code> if partitioning changed - */ - boolean documentChanged(DocumentEvent event); - - /** - * Returns the set of all legal content types of this partitioner. - * I.e. any result delivered by this partitioner may not contain a content type - * which would not be included in this method's result. - * - * @return the set of legal content types - */ - String[] getLegalContentTypes(); - - /** - * Returns the content type of the partition containing the - * given offset in the connected document. There must be a - * document connected to this partitioner. - * - * @param offset the offset in the connected document - * @return the content type of the offset's partition - */ - String getContentType(int offset); - - /** - * Returns the partitioning of the given range of the connected - * document. There must be a document connected to this partitioner. - * - * @param offset the offset of the range of interest - * @param length the length of the range of interest - * @return the partitioning of the range - */ - ITypedRegion[] computePartitioning(int offset, int length); - - /** - * Returns the partition containing the given offset of - * the connected document. There must be a document connected to this - * partitioner. - * - * @param offset the offset for which to determine the partition - * @return the partition containing the offset - */ - ITypedRegion getPartition(int offset); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java deleted file mode 100644 index 34eda1f984c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension.java +++ /dev/null @@ -1,37 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Extension interface for <code>IDocumentPartitioner</code>. Extends the original - * concept of a document partitioner by returning the minimal region that includes all - * partition changes causes by the invocation of the document partitioner. - * - * @since 2.0 - -*/ -public interface IDocumentPartitionerExtension { - - /** - * The document has been changed. The partitioner updates - * the document's partitioning and returns in which region the - * partition types have changed. This method always returns - * the surrounding region. Will be called by the connected document - * and is not intended to be used by clients other than the connected - * document. - * - * @param event the event describing the document change - * @return the region of the document in which the partition type changed - */ - IRegion documentChanged2(DocumentEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java deleted file mode 100644 index 59e2cbabc7a..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListener.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Interface of objects which are interested in getting informed - * about changes of a document's partitioning. Clients may - * implement this interface. - * - * @see IDocument - * @see IDocumentPartitioner - */ -public interface IDocumentPartitioningListener { - - /** - * The partitioning of the given document changed. - * - * @param document the document whose partitioning changed - * - * @see IDocument#addDocumentPartitioningListener - */ - void documentPartitioningChanged(IDocument document); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java deleted file mode 100644 index 3ae89d44109..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitioningListenerExtension.java +++ /dev/null @@ -1,33 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Extension interface for <code>IDocumentPartitioningListener</code>. Extends the original - * partitioning listener concept by telling the listener the minimal region that comprises all - * partitioning changes. - * - * @see org.eclipse.jface.text.IDocumentPartitionerExtension - * @since 2.0 - */ -public interface IDocumentPartitioningListenerExtension { - - /** - * The partitioning of the given document changed in the given region. - * - * @param document the document whose partitioning changed - * @param region the region in which the partitioning changed - * @see IDocument#addDocumentPartitioningListener - */ - void documentPartitioningChanged(IDocument document, IRegion region); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java deleted file mode 100644 index 3c07ac42255..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ILineTracker.java +++ /dev/null @@ -1,136 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -/** - * A line tracker maps character positions to line numbers and vice versa. - * Initially the line tracker is informed about its underlying text which - * in order to initialize the mapping information. After that, the line - * tracker is informed about all changes of the underlying text allowing - * for incremental updates of the mapping information. It is the client's - * responsibility to actively inform the line tacker about text changes. - * For example, when using a line tracker in combination with a document - * the document controls the line tracker.<p> - * Clients may implement this interface or use the standard implementation - * <code>DefaultLineTracker</code>. - */ -public interface ILineTracker { - - /** - * Returns the strings this tracker considers as legal line delimiters. - * - * @return the legal line delimiters - */ - String[] getLegalLineDelimiters(); - - /** - * Returns the line delimiter of the specified line. Returns null if the - * line is not closed with a line delimiter. - * - * @param line the line whose line delimiter is queried - * @return the line's delimiter or <code>null</code> if line does not have a delimiter - * @exception BadLocationException if the line number is invalid in this tracker's line structure - */ - String getLineDelimiter(int line) throws BadLocationException; - - /** - * Computes the number of lines in the given text. - * - * @param text the text whose number of lines should be computed - * @return the number of lines in the given text - */ - int computeNumberOfLines(String text); - - /** - * Returns the number of lines. - * - * @return the number of lines in this tracker's line structure - */ - int getNumberOfLines(); - - /** - * Returns the number of lines which are occupied by a given text range. - * - * @param offset the offset of the specified text range - * @param length the length of the specified text range - * @return the number of lines occupied by the specified range - * @exception BadLocationException if specified range is unknown to this tracker - */ - int getNumberOfLines(int offset, int length) throws BadLocationException; - - /** - * Returns the position of the first character of the specified line. - * - * @param line the line of interest - * @return offset of the first character of the line - * @exception BadLocationException if the line is unknown to this tracker - */ - int getLineOffset(int line) throws BadLocationException; - - /** - * Returns length of the specified line including the line's delimiter. - * - * @param line the line of interest - * @return the length of the line - * @exception BadLocationException if line is unknown to this tracker - */ - int getLineLength(int line) throws BadLocationException; - - /** - * Returns the line number the character at the given offset belongs to. - * - * @param offset the offset whose line number to be determined - * @return the number of the line the offset is on - * @exception BadLocationException if the offset is invalid in this tracker - */ - int getLineNumberOfOffset(int offset) throws BadLocationException; - - /** - * Returns a line description of the line at the given offset. - * The description contains the start offset and the length of the line - * excluding the line's delimiter. - * - * @param offset the offset whose line should be described - * @return a region describing the line - * @exception BadLocationException if offset is invalid in this tracker - */ - IRegion getLineInformationOfOffset(int offset) throws BadLocationException; - - /** - * Returns a line description of the given line. The description - * contains the start offset and the length of the line excluding the line's - * delimiter. - * - * @param line the line that should be described - * @return a region describing the line - * @exception BadLocationException if line is unknown to this tracker - */ - IRegion getLineInformation(int line) throws BadLocationException; - - /** - * Informs the line tracker about the specified change in the tracked text. - * - * @param offset the offset of the replaced text - * @param length the length of the replaced text - * @param text the substitution text - * @exception BadLocationException if specified range is unknown to this tracker - */ - void replace(int offset, int length, String text) throws BadLocationException; - - /** - * Sets the tracked text to the specified text. - * - * @param text the new tracked text - */ - void set(String text); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java b/org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java deleted file mode 100644 index 590b57db4a9..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IPositionUpdater.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * A position updater is responsible for adapting document positions. - * When installed on a document, the position updater updates the - * document's positions to changes applied to this document. Document - * updaters can be selective, i.e. they might only update positions of - * a certain category.<p> - * Position updaters are of primary importance for the definition of - * the semantics of positions.<p> - * Clients may implement this interface or use the standard implementation - * <code>DefaultPositionUpdater</code>. - * - * @see IDocument - * @see Position - */ -public interface IPositionUpdater { - - /** - * Adapts positions to the change specified by the document event. - * It is ensured that the document's partitioning has been adapted to - * this document change and that all the position updaters which have - * a smaller index in the document's position updater list have been called. - * - * @param event the document event describing the document change - */ - void update(DocumentEvent event); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IRegion.java b/org.eclipse.text/src/org/eclipse/jface/text/IRegion.java deleted file mode 100644 index d3edc67400d..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/IRegion.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * A region describes a certain range in an indexed text store. - * Text stores are for example documents or strings. A region is - * defined by its offset into the text store and its length.<p> - * A region is considered a value object. Its offset or length - * do not change over time. <p> - * Clients may implement this interface or use the standard implementation - * <code>Region</code>. - */ -public interface IRegion { - - /** - * Returns the length of the region. - * - * @return the length of the region - */ - int getLength(); - - /** - * Returns the offset of the region. - * - * @return the offset of the region - */ - int getOffset(); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java deleted file mode 100644 index a82894bdfbb..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ITextStore.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * Interface for storing and managing text. - * Provides access to the stored text and allows to manipulate it. - * Clients may implement this interface. - */ -public interface ITextStore { - - /** - * Returns the character at the specified offset. - * - * @param offset the offset in this text store - * @return the character at this offset - */ - char get(int offset); - - /** - * Returns the text of the specified character range. - * - * @param offset the offset of the range - * @param length the length of the range - * @return the text of the range - */ - String get(int offset, int length); - - /** - * Returns number of characters stored in this text store. - * - * @return the number of characters stored in this text store - */ - int getLength(); - - /** - * Replaces the specified character range with the given text. - * <code>replace(getLength(), 0, "some text")</code> is a valid - * call and appends text to the end of the text store. - * - * @param offset the offset of the range to be replaced - * @param length the number of characters to be replaced - * @param text the substitution text - */ - void replace(int offset, int length, String text); - - /** - * Replace the content of the text store with the given text. - * Convenience method for <code>replace(0, getLength(), text</code>. - * - * @param text the new content of the text store - */ - void set(String text); -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java b/org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java deleted file mode 100644 index 9cd573a83a5..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/ITypedRegion.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Describes a region of an indexed text store such as document or string. - * The region consists of offset, length, and type. The type is defines as - * a string. A typed region can, e.g., be used to described document partitions. - * Clients may implement this interface or use the standard impementation - * <code>TypedRegion</code>. - */ -public interface ITypedRegion extends IRegion { - - /** - * Returns the content type of the region. - * - * @return the content type of the region - */ - String getType(); -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Line.java b/org.eclipse.text/src/org/eclipse/jface/text/Line.java deleted file mode 100644 index ab39bfd1701..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Line.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Describes a line as a particular number of characters beginning at - * a particular offset, consisting of a particular number of characters, - * and being closed with a particular line delimiter. - */ -class Line implements IRegion { - - /** The offset of the line */ - public int offset; - /** The length of the line */ - public int length; - /** The delimiter of this line */ - public String delimiter; - - /** - * Creates a new Line. - * - * @param offset the offset of the line - * @param end the last including character offset of the line - * @param delimiter the line's delimiter - */ - public Line(int offset, int end, String delimiter) { - this.offset= offset; - this.length= (end - offset) +1; - this.delimiter= delimiter; - } - - /** - * Creates a new Line. - * - * @param offset the offset of the line - * @param length the length of the line - */ - public Line(int offset, int length) { - this.offset= offset; - this.length= length; - this.delimiter= null; - } - - /* - * @see IRegion#getOffset() - */ - public int getOffset() { - return offset; - } - - /* - * @see IRegion#getLength() - */ - public int getLength() { - return length; - } -} - - diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Position.java b/org.eclipse.text/src/org/eclipse/jface/text/Position.java deleted file mode 100644 index 08737da6d99..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Position.java +++ /dev/null @@ -1,181 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - - -/** - * Positions describe text ranges of a document and are - * adapted to changes applied to that document. The text range - * is specified by an offset and a length. Positions can be marked as - * deleted. Deleted positions are considered to no longer represent - * a valid text range in the managing document. <p> - * Positions attached to documents are ususally updated by position updaters. - * Because position updaters are freely defineable and because of the - * frequence in which they are used, the fields of a position are made - * publicly accessible. Clients other than position updaters are not - * allowed to access these public fields. - * - * @see IDocument - */ -public class Position { - - /** The offset of the position */ - public int offset; - /** The length of the position */ - public int length; - /** Indicates whether the position has been deleted */ - public boolean isDeleted; - - /** - * Creates a new position with the given offset and length 0. - * - * @param offset the position offset, must be >= 0 - */ - public Position(int offset) { - this(offset, 0); - } - - /** - * Creates a new position with the given offset and length. - * - * @param offset the position offset, must be >= 0 - * @param length the position length, must be >= 0 - */ - public Position(int offset, int length) { - Assert.isTrue(offset >= 0); - Assert.isTrue(length >= 0); - this.offset= offset; - this.length= length; - } - - /* - * @see Object#hashCode - */ - public int hashCode() { - int deleted= isDeleted ? 0 : 1; - return (offset << 24) | (length << 16) | deleted; - } - - /** - * Marks this position as deleted. - */ - public void delete() { - isDeleted= true; - } - - /** - * Marks this position as not deleted. - * @since 2.0 - */ - public void undelete() { - isDeleted= false; - } - - /* - * @see Object#equals - */ - public boolean equals(Object other) { - if (other instanceof Position) { - Position rp= (Position) other; - return (rp.offset == offset) && (rp.length == length); - } - return super.equals(other); - } - - /** - * Returns the length of this position. - * - * @return the length of this position - */ - public int getLength() { - return length; - } - - /** - * Returns the offset of this position. - * - * @return the length of this position - */ - public int getOffset() { - return offset; - } - - /** - * Checks whether the given offset is inside - * of this position's text range. - * - * @param offset the offset to check - * @return <code>true</code> if offset is inside of this position - */ - public boolean includes(int offset) { - - if (isDeleted) - return false; - - return (this.offset <= offset) && (offset < this.offset + length); - } - - /** - * Checks whether the intersection of the given text range - * and the text range represented by this position is empty - * or not. - * - * @param offset the offset of the range to check - * @param length the length of the range to check - * @return <code>true</code> if intersection is not empty - */ - public boolean overlapsWith(int offset, int length) { - - if (isDeleted) - return false; - - int end= offset + length; - int thisEnd= this.offset + this.length; - - if (length > 0) { - if (this.length > 0) - return this.offset < end && offset < thisEnd; - return offset <= this.offset && this.offset < end; - } - - if (this.length > 0) - return this.offset <= offset && offset < thisEnd; - return this.offset == offset; - } - - /** - * Returns whether this position has been deleted or not. - * - * @return <code>true</code> if position has been deleted - */ - public boolean isDeleted() { - return isDeleted; - } - - /** - * Changes the length of this position to the given length. - * - * @param length the new length of this position - */ - public void setLength(int length) { - this.length= length; - } - - /** - * Changes the offset of this position to the given offset. - * - * @param offset the new offset of this position - */ - public void setOffset(int offset) { - this.offset= offset; - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/Region.java b/org.eclipse.text/src/org/eclipse/jface/text/Region.java deleted file mode 100644 index 98a65d9bbd1..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/Region.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * A default implementation of the <code>IRegion</code> interface. - */ -public class Region implements IRegion { - - /** The region offset */ - private int fOffset; - /** The region length */ - private int fLength; - - /** - * Create a new region. - * - * @param offset the offset of the region - * @param length the length of the region - */ - public Region(int offset, int length) { - fOffset= offset; - fLength= length; - } - - /* - * @see IRegion#getLength - */ - public int getLength() { - return fLength; - } - - /* - * @see IRegion#getOffset - */ - public int getOffset() { - return fOffset; - } - - /** - * Two regions are equal if they have the same offset and length. - * - * @see Object#equals - */ - public boolean equals(Object o) { - if (o instanceof IRegion) { - IRegion r= (IRegion) o; - return r.getOffset() == fOffset && r.getLength() == fLength; - } - return false; - } - - /* - * @see Object#hashCode - */ - public int hashCode() { - return (fOffset << 24) | (fLength << 16); - } -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java deleted file mode 100644 index 9856a272cf0..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java +++ /dev/null @@ -1,273 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.jface.text; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - - -/** - * A text store that optimizes a given source text store for sequential rewriting. - * While rewritten it keeps a list of replace command that serve as patches for - * the source store. Only on request, the source store is indeed manipulated - * by applying the patch commands to the source text store. - * - * @since 2.0 - */ -public class SequentialRewriteTextStore implements ITextStore { - - /** - * A buffered replace command. - */ - private static class Replace { - public int newOffset; - public final int offset; - public final int length; - public final String text; - - public Replace(int offset, int newOffset, int length, String text) { - this.newOffset= newOffset; - this.offset= offset; - this.length= length; - this.text= text; - } - } - - /** The list of buffered replacements. */ - private List fReplaceList; - /** The source text store */ - private ITextStore fSource; - /** A flag to enforce sequential access. */ - private static final boolean ASSERT_SEQUENTIALITY= false; - - - /** - * Creates a new sequential rewrite store for the given source store. - * - * @param source the source text store - */ - public SequentialRewriteTextStore(ITextStore source) { - fReplaceList= new LinkedList(); - fSource= source; - } - - /** - * Returns the source store of this rewrite store. - * - * @return the source store of this rewrite store - */ - public ITextStore getSourceStore() { - commit(); - return fSource; - } - - /* - * @see ITextStore#replace(int, int, String) - */ - public void replace(int offset, int length, String text) { - - if (fReplaceList.size() == 0) { - fReplaceList.add(new Replace(offset, offset, length, text)); - - } else { - Replace firstReplace= (Replace) fReplaceList.get(0); - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - - // backward - if (offset + length <= firstReplace.newOffset) { - int delta= text.length() - length; - if (delta != 0) { - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - replace.newOffset += delta; - } - } - - fReplaceList.add(0, new Replace(offset, offset, length, text)); - - // forward - } else if (offset >= lastReplace.newOffset + lastReplace.text.length()) { - int delta= getDelta(lastReplace); - fReplaceList.add(new Replace(offset - delta, offset, length, text)); - - } else if (ASSERT_SEQUENTIALITY) { - throw new IllegalArgumentException(); - - } else { - commit(); - fSource.replace(offset, length, text); - } - } - } - - /* - * @see ITextStore#set(String) - */ - public void set(String text) { - fSource.set(text); - fReplaceList.clear(); - } - - /* - * @see ITextStore#get(int, int) - */ - public String get(int offset, int length) { - - if (fReplaceList.size() == 0) { - return fSource.get(offset, length); - - } else { - Replace firstReplace= (Replace) fReplaceList.get(0); - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - - // before - if (offset + length <= firstReplace.newOffset) { - return fSource.get(offset, length); - - // after - } else if (offset >= lastReplace.newOffset + lastReplace.text.length()) { - int delta= getDelta(lastReplace); - return fSource.get(offset - delta, length); - - } else if (ASSERT_SEQUENTIALITY) { - throw new IllegalArgumentException(); - - } else { - - int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - - if (offset + length < replace.newOffset) { - return fSource.get(offset - delta, length); - - } else if (offset >= replace.newOffset && offset + length <= replace.newOffset + replace.text.length()) { - return replace.text.substring(offset - replace.newOffset, length); - - } else if (offset >= replace.newOffset + replace.text.length()) { - delta= getDelta(replace); - continue; - - } else { - commit(); - return fSource.get(offset, length); - } - } - - return fSource.get(offset - delta, length); - } - } - } - - /** - * Returns the difference between the offset in the source store and the "same" offset in the - * rewrite store after the replace operation. - * - * @param replace the replace command - */ - private static final int getDelta(Replace replace) { - return replace.newOffset - replace.offset + replace.text.length() - replace.length; - } - - /* - * @see ITextStore#get(int) - */ - public char get(int offset) { - if (fReplaceList.size() == 0) { - return fSource.get(offset); - - } else { - Replace firstReplace= (Replace) fReplaceList.get(0); - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - - // before - if (offset < firstReplace.newOffset) { - return fSource.get(offset); - - // after - } else if (offset >= lastReplace.newOffset + lastReplace.text.length()) { - int delta= getDelta(lastReplace); - return fSource.get(offset - delta); - - } else if (ASSERT_SEQUENTIALITY) { - throw new IllegalArgumentException(); - - } else { - - int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - - if (offset < replace.newOffset) - return fSource.get(offset - delta); - - else if (offset < replace.newOffset + replace.text.length()) - return replace.text.charAt(offset - replace.newOffset); - - delta= getDelta(replace); - } - - return fSource.get(offset - delta); - } - } - } - - /* - * @see ITextStore#getLength() - */ - public int getLength() { - if (fReplaceList.size() == 0) { - return fSource.getLength(); - - } else { - Replace lastReplace= (Replace) fReplaceList.get(fReplaceList.size() - 1); - return fSource.getLength() + getDelta(lastReplace); - } - } - - /** - * Disposes this rewrite store. - */ - public void dispose() { - fReplaceList= null; - fSource= null; - } - - /** - * Commits all buffered replace commands. - */ - private void commit() { - - if (fReplaceList.size() == 0) - return; - - StringBuffer buffer= new StringBuffer(); - - int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); - - int offset= buffer.length() - delta; - buffer.append(fSource.get(offset, replace.offset - offset)); - buffer.append(replace.text); - delta= getDelta(replace); - } - - int offset= buffer.length() - delta; - buffer.append(fSource.get(offset, fSource.getLength() - offset)); - - fSource.set(buffer.toString()); - fReplaceList.clear(); - } - -} diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java deleted file mode 100644 index 9aea7a4e0b5..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Collection of text functions. - */ -public class TextUtilities { - - - public final static String[] fgDelimiters= new String[] { "\n", "\r", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - - - /** - * Determines which one of fgDelimiters appears first in the list. If none of them the - * hint is returned. - */ - public static String determineLineDelimiter(String text, String hint) { - try { - int[] info= indexOf(fgDelimiters, text, 0); - return fgDelimiters[info[1]]; - } catch (ArrayIndexOutOfBoundsException x) { - } - return hint; - } - - /** - * Returns the position in the string greater than offset - * of the longest matching search string. - */ - public static int[] indexOf(String[] searchStrings, String text, int offset) { - - int[] result= { -1, -1 }; - int zeroIndex= -1; - - for (int i= 0; i < searchStrings.length; i++) { - - int length= searchStrings[i].length(); - - if (length == 0) { - zeroIndex= i; - continue; - } - - int index= text.indexOf(searchStrings[i], offset); - if (index >= 0) { - - if (result[0] == -1) { - result[0]= index; - result[1]= i; - } else if (index < result[0]) { - result[0]= index; - result[1]= i; - } else if (index == result[0] && length > searchStrings[result[1]].length()) { - result[0]= index; - result[1]= i; - } - } - } - - if (zeroIndex > -1 && result[0] == -1) { - result[0]= 0; - result[1]= zeroIndex; - } - - return result; - } - - /** - * Returns the longest search string with which the given text ends. - */ - public static int endsWith(String[] searchStrings, String text) { - - int index= -1; - - for (int i= 0; i < searchStrings.length; i++) { - if (text.endsWith(searchStrings[i])) { - if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) - index= i; - } - } - - return index; - } - - /** - * Returns the longest search string with which the given text starts. - */ - public static int startsWith(String[] searchStrings, String text) { - - int index= -1; - - for (int i= 0; i < searchStrings.length; i++) { - if (text.startsWith(searchStrings[i])) { - if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) - index= i; - } - } - - return index; - } - - /** - * Returns whether the text equals one of the given compare strings. - */ - public static int equals(String[] compareStrings, String text) { - for (int i= 0; i < compareStrings.length; i++) { - if (text.equals(compareStrings[i])) - return i; - } - return -1; - } -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java b/org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java deleted file mode 100644 index bec400808f7..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/TypedPosition.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Convenience class for position like typed regions. - */ -public class TypedPosition extends Position { - - /** The type of the region described by this position */ - private String fType; - - /** - * Creates a position along the given specification. - * - * @param offset the offset of this position - * @param length the length of this position - * @param type the type of this position - */ - public TypedPosition(int offset, int length, String type) { - super(offset, length); - fType= type; - } - - /** - * Creates a position based on the typed region. - * - * @param region the typed region - */ - public TypedPosition(ITypedRegion region) { - super(region.getOffset(), region.getLength()); - fType= region.getType(); - } - - /** - * Returns the type of the position - * - * @return the type of this position - */ - public String getType() { - return fType; - } - - /* - * @see Object#equals - */ - public boolean equals(Object o) { - if (o instanceof TypedPosition) { - if (super.equals(o)) { - TypedPosition p= (TypedPosition) o; - return (fType == null && p.getType() == null) || fType.equals(p.getType()); - } - } - return false; - } - - /* - * @see Object#hashCode - */ - public int hashCode() { - int type= fType == null ? 0 : fType.hashCode(); - return super.hashCode() | type; - } -}
\ No newline at end of file diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java b/org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java deleted file mode 100644 index f45eeb6532c..00000000000 --- a/org.eclipse.text/src/org/eclipse/jface/text/TypedRegion.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.eclipse.jface.text; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Default implementation of <code>ITypedRegion</code>. - */ -public class TypedRegion extends Region implements ITypedRegion { - - /** The region's type */ - private String fType; - - /** - * Creates a typed region based on the given specification. - * - * @param offset the region's offset - * @param length the region's length - * @param type the region's type - */ - public TypedRegion(int offset, int length, String type) { - super(offset, length); - fType= type; - } - - /* - * @see ITypedRegion#getType() - */ - public String getType() { - return fType; - } - - /** - * Two typed positions are equal if they have the same offset, length, and type. - * - * @see Object#equals - */ - public boolean equals(Object o) { - if (o instanceof TypedRegion) { - TypedRegion r= (TypedRegion) o; - return super.equals(r) && ((fType == null && r.getType() == null) || fType.equals(r.getType())); - } - return false; - } - - /* - * @see Object#hashCode - */ - public int hashCode() { - int type= fType == null ? 0 : fType.hashCode(); - return super.hashCode() | type; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.examples.javaeditor/.classpath b/org.eclipse.ui.examples.javaeditor/.classpath deleted file mode 100644 index 973aed0d7ef..00000000000 --- a/org.eclipse.ui.examples.javaeditor/.classpath +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="Eclipse Java Editor Example"/> - <classpathentry kind="src" path="/org.eclipse.ui"/> - <classpathentry kind="src" path="/org.eclipse.swt"/> - <classpathentry kind="src" path="/org.eclipse.core.resources"/> - <classpathentry kind="src" path="/org.eclipse.core.runtime"/> - <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/org.eclipse.ui.examples.javaeditor/.cvsignore b/org.eclipse.ui.examples.javaeditor/.cvsignore deleted file mode 100644 index c5e82d74585..00000000000 --- a/org.eclipse.ui.examples.javaeditor/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin
\ No newline at end of file diff --git a/org.eclipse.ui.examples.javaeditor/.project b/org.eclipse.ui.examples.javaeditor/.project deleted file mode 100644 index afe248a3b87..00000000000 --- a/org.eclipse.ui.examples.javaeditor/.project +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.ui.examples.javaeditor</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.ui</project>
- <project>org.eclipse.core.runtime</project>
- <project>org.eclipse.swt</project>
- <project>org.eclipse.core.resources</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java deleted file mode 100644 index aba3eedc87d..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ResourceBundle;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.editors.text.TextEditorActionContributor;
-import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.RetargetTextEditorAction;
-import org.eclipse.ui.texteditor.TextEditorAction;
-
-/**
- * Contributes interesting Java actions to the desktop's Edit menu and the toolbar.
- */
-public class JavaActionContributor extends TextEditorActionContributor {
-
- protected RetargetTextEditorAction fContentAssistProposal;
- protected RetargetTextEditorAction fContentAssistTip;
- protected TextEditorAction fTogglePresentation;
-
- /**
- * Default constructor.
- */
- public JavaActionContributor() {
- super();
- fContentAssistProposal= new RetargetTextEditorAction(JavaEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
- fContentAssistTip= new RetargetTextEditorAction(JavaEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
- fTogglePresentation= new PresentationAction();
- }
-
- /*
- * @see IEditorActionBarContributor#init(IActionBars)
- */
- public void init(IActionBars bars) {
- super.init(bars);
-
- IMenuManager menuManager= bars.getMenuManager();
- IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
- if (editMenu != null) {
- editMenu.add(new Separator());
- editMenu.add(fContentAssistProposal);
- editMenu.add(fContentAssistTip);
- }
-
- IToolBarManager toolBarManager= bars.getToolBarManager();
- if (toolBarManager != null) {
- toolBarManager.add(new Separator());
- toolBarManager.add(fTogglePresentation);
- }
- }
-
- private void doSetActiveEditor(IEditorPart part) {
- super.setActiveEditor(part);
-
- ITextEditor editor= null;
- if (part instanceof ITextEditor)
- editor= (ITextEditor) part;
-
- fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$
- fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
-
- fTogglePresentation.setEditor(editor);
- fTogglePresentation.update();
- }
-
- /*
- * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
- */
- public void setActiveEditor(IEditorPart part) {
- super.setActiveEditor(part);
- doSetActiveEditor(part);
- }
-
- /*
- * @see IEditorActionBarContributor#dispose()
- */
- public void dispose() {
- doSetActiveEditor(null);
- super.dispose();
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java deleted file mode 100644 index 676e4856b98..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-/**
- * The JavaAnnotationHover provides the hover support for java editors.
- */
-
-public class JavaAnnotationHover implements IAnnotationHover {
-
- /* (non-Javadoc)
- * Method declared on IAnnotationHover
- */
- public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
- IDocument document= sourceViewer.getDocument();
-
- try {
- IRegion info= document.getLineInformation(lineNumber);
- return document.get(info.getOffset(), info.getLength());
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java deleted file mode 100644 index f4f2d466c66..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java +++ /dev/null @@ -1,244 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
-
-/**
- * A content outline page which always represents the content of the
- * connected editor in 10 segments.
- */
-public class JavaContentOutlinePage extends ContentOutlinePage {
-
- /**
- * A segment element.
- */
- protected static class Segment {
- public String name;
- public Position position;
-
- public Segment(String name, Position position) {
- this.name= name;
- this.position= position;
- }
-
- public String toString() {
- return name;
- }
- };
-
- /**
- * Divides the editor's document into ten segments and provides elements for them.
- */
- protected class ContentProvider implements ITreeContentProvider {
-
- protected final static String SEGMENTS= "__java_segments"; //$NON-NLS-1$
- protected IPositionUpdater fPositionUpdater= new DefaultPositionUpdater(SEGMENTS);
- protected List fContent= new ArrayList(10);
-
- protected void parse(IDocument document) {
-
- int lines= document.getNumberOfLines();
- int increment= Math.max(Math.round((float) (lines / 10)), 10);
-
- for (int line= 0; line < lines; line += increment) {
-
- int length= increment;
- if (line + increment > lines)
- length= lines - line;
-
- try {
-
- int offset= document.getLineOffset(line);
- int end= document.getLineOffset(line + length);
- length= end - offset;
- Position p= new Position(offset, length);
- document.addPosition(SEGMENTS, p);
- fContent.add(new Segment(MessageFormat.format(JavaEditorMessages.getString("OutlinePage.segment.title_pattern"), new Object[] { new Integer(offset) }), p)); //$NON-NLS-1$
-
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
- }
- }
-
- /*
- * @see IContentProvider#inputChanged(Viewer, Object, Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (oldInput != null) {
- IDocument document= fDocumentProvider.getDocument(oldInput);
- if (document != null) {
- try {
- document.removePositionCategory(SEGMENTS);
- } catch (BadPositionCategoryException x) {
- }
- document.removePositionUpdater(fPositionUpdater);
- }
- }
-
- fContent.clear();
-
- if (newInput != null) {
- IDocument document= fDocumentProvider.getDocument(newInput);
- if (document != null) {
- document.addPositionCategory(SEGMENTS);
- document.addPositionUpdater(fPositionUpdater);
-
- parse(document);
- }
- }
- }
-
- /*
- * @see IContentProvider#dispose
- */
- public void dispose() {
- if (fContent != null) {
- fContent.clear();
- fContent= null;
- }
- }
-
- /*
- * @see IContentProvider#isDeleted(Object)
- */
- public boolean isDeleted(Object element) {
- return false;
- }
-
- /*
- * @see IStructuredContentProvider#getElements(Object)
- */
- public Object[] getElements(Object element) {
- return fContent.toArray();
- }
-
- /*
- * @see ITreeContentProvider#hasChildren(Object)
- */
- public boolean hasChildren(Object element) {
- return element == fInput;
- }
-
- /*
- * @see ITreeContentProvider#getParent(Object)
- */
- public Object getParent(Object element) {
- if (element instanceof Segment)
- return fInput;
- return null;
- }
-
- /*
- * @see ITreeContentProvider#getChildren(Object)
- */
- public Object[] getChildren(Object element) {
- if (element == fInput)
- return fContent.toArray();
- return new Object[0];
- }
- };
-
- protected Object fInput;
- protected IDocumentProvider fDocumentProvider;
- protected ITextEditor fTextEditor;
-
- /**
- * Creates a content outline page using the given provider and the given editor.
- */
- public JavaContentOutlinePage(IDocumentProvider provider, ITextEditor editor) {
- super();
- fDocumentProvider= provider;
- fTextEditor= editor;
- }
-
- /* (non-Javadoc)
- * Method declared on ContentOutlinePage
- */
- public void createControl(Composite parent) {
-
- super.createControl(parent);
-
- TreeViewer viewer= getTreeViewer();
- viewer.setContentProvider(new ContentProvider());
- viewer.setLabelProvider(new LabelProvider());
- viewer.addSelectionChangedListener(this);
-
- if (fInput != null)
- viewer.setInput(fInput);
- }
-
- /* (non-Javadoc)
- * Method declared on ContentOutlinePage
- */
- public void selectionChanged(SelectionChangedEvent event) {
-
- super.selectionChanged(event);
-
- ISelection selection= event.getSelection();
- if (selection.isEmpty())
- fTextEditor.resetHighlightRange();
- else {
- Segment segment= (Segment) ((IStructuredSelection) selection).getFirstElement();
- int start= segment.position.getOffset();
- int length= segment.position.getLength();
- try {
- fTextEditor.setHighlightRange(start, length, true);
- } catch (IllegalArgumentException x) {
- fTextEditor.resetHighlightRange();
- }
- }
- }
-
- /**
- * Sets the input of the outline page
- */
- public void setInput(Object input) {
- fInput= input;
- update();
- }
-
- /**
- * Updates the outline page.
- */
- public void update() {
- TreeViewer viewer= getTreeViewer();
-
- if (viewer != null) {
- Control control= viewer.getControl();
- if (control != null && !control.isDisposed()) {
- control.setRedraw(false);
- viewer.setInput(fInput);
- viewer.expandAll();
- control.setRedraw(true);
- }
- }
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java deleted file mode 100644 index 7bcbb08c450..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.rules.DefaultPartitioner;
-import org.eclipse.jface.text.rules.RuleBasedPartitioner;
-import org.eclipse.ui.editors.text.FileDocumentProvider;
-import org.eclipse.ui.examples.javaeditor.java.JavaPartitionScanner;
-
-/**
- * The JavaDocumentProvider provides the IDocuments used by java editors.
- */
-
-public class JavaDocumentProvider extends FileDocumentProvider {
-
- private final static String[] TYPES= new String[] { JavaPartitionScanner.JAVA_DOC, JavaPartitionScanner.JAVA_MULTILINE_COMMENT };
-
- private static JavaPartitionScanner fgScanner= null;
-
- public JavaDocumentProvider() {
- super();
- }
-
- /* (non-Javadoc)
- * Method declared on AbstractDocumentProvider
- */
- protected IDocument createDocument(Object element) throws CoreException {
- IDocument document= super.createDocument(element);
- if (document != null) {
- IDocumentPartitioner partitioner= createJavaPartitioner();
- document.setDocumentPartitioner(partitioner);
- partitioner.connect(document);
- }
- return document;
- }
-
- /**
- * Return a partitioner for .java files.
- */
- private IDocumentPartitioner createJavaPartitioner() {
- return new DefaultPartitioner(getJavaPartitionScanner(), TYPES);
- }
-
- /**
- * Return a scanner for creating java partitions.
- */
- private JavaPartitionScanner getJavaPartitionScanner() {
- if (fgScanner == null)
- fgScanner= new JavaPartitionScanner();
- return fgScanner;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java deleted file mode 100644 index af6f88eb2ee..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java +++ /dev/null @@ -1,134 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ResourceBundle;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.texteditor.DefaultRangeIndicator;
-import org.eclipse.ui.texteditor.TextOperationAction;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-
-/**
- * Java specific text editor.
- */
-public class JavaEditor extends TextEditor {
-
- /** The outline page */
- private JavaContentOutlinePage fOutlinePage;
-
- /**
- * Default constructor.
- */
- public JavaEditor() {
- super();
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method extend the
- * actions to add those specific to the receiver
- */
- protected void createActions() {
- super.createActions();
- setAction("ContentAssistProposal", new TextOperationAction(JavaEditorMessages.getResourceBundle(), "ContentAssistProposal.", this, ISourceViewer.CONTENTASSIST_PROPOSALS)); //$NON-NLS-1$ //$NON-NLS-2$
- setAction("ContentAssistTip", new TextOperationAction(JavaEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method performs any extra
- * disposal actions required by the java editor.
- */
- public void dispose() {
- JavaEditorEnvironment.disconnect(this);
- if (fOutlinePage != null)
- fOutlinePage.setInput(null);
- super.dispose();
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method performs any extra
- * revert behavior required by the java editor.
- */
- public void doRevertToSaved() {
- super.doRevertToSaved();
- if (fOutlinePage != null)
- fOutlinePage.update();
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method performs any extra
- * save behavior required by the java editor.
- */
- public void doSave(IProgressMonitor monitor) {
- super.doSave(monitor);
- if (fOutlinePage != null)
- fOutlinePage.update();
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method performs any extra
- * save as behavior required by the java editor.
- */
- public void doSaveAs() {
- super.doSaveAs();
- if (fOutlinePage != null)
- fOutlinePage.update();
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method performs sets the
- * input of the outline page after AbstractTextEditor has set input.
- */
- public void doSetInput(IEditorInput input) throws CoreException {
- super.doSetInput(input);
- if (fOutlinePage != null)
- fOutlinePage.setInput(input);
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method adds any
- * JavaEditor specific entries.
- */
- public void editorContextMenuAboutToShow(MenuManager menu) {
- super.editorContextMenuAboutToShow(menu);
- addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
- addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
- }
-
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method performs gets
- * the java content outline page if request is for a an
- * outline page.
- */
- public Object getAdapter(Class required) {
- if (IContentOutlinePage.class.equals(required)) {
- if (fOutlinePage == null) {
- fOutlinePage= new JavaContentOutlinePage(getDocumentProvider(), this);
- if (getEditorInput() != null)
- fOutlinePage.setInput(getEditorInput());
- }
- return fOutlinePage;
- }
- return super.getAdapter(required);
- }
-
- /* (non-Javadoc)
- * Method declared on AbstractTextEditor
- */
- protected void initializeEditor() {
-
- JavaEditorEnvironment.connect(this);
-
- setSourceViewerConfiguration(new JavaSourceViewerConfiguration());
- setRangeIndicator(new DefaultRangeIndicator());
- setEditorContextMenuId("#JavaEditorContext"); //$NON-NLS-1$
- setRulerContextMenuId("#JavaRulerContext"); //$NON-NLS-1$
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java deleted file mode 100644 index 5849127c54b..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.ui.examples.javaeditor.java.JavaCodeScanner;
-import org.eclipse.ui.examples.javaeditor.javadoc.JavaDocScanner;
-import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
-
-/** The JavaEditorEnvironment maintains singletons used by the java editor
- * examples.
- */
-public class JavaEditorEnvironment {
-
- private static JavaColorProvider fgColorProvider;
- private static JavaCodeScanner fgCodeScanner;
- private static JavaDocScanner fgDocScanner;
-
- private static int fgRefCount= 0;
-
- /**
- * A connection has occured - initialize the receiver if it is the first activation.
- */
- public static void connect(Object client) {
- if (++fgRefCount == 1) {
- fgColorProvider= new JavaColorProvider();
- fgCodeScanner= new JavaCodeScanner(fgColorProvider);
- fgDocScanner= new JavaDocScanner(fgColorProvider);
- }
- }
-
- /**
- * A disconnection has occured - clear the receiver if it is the last deactivation.
- */
- public static void disconnect(Object client) {
- if (--fgRefCount == 0) {
- fgCodeScanner= null;
- fgDocScanner= null;
- fgColorProvider.dispose();
- fgColorProvider= null;
- }
- }
-
- /**
- * Returns the singleton scanner.
- */
- public static RuleBasedScanner getJavaCodeScanner() {
- return fgCodeScanner;
- }
-
- /**
- * Returns the singleton color provider.
- */
- public static JavaColorProvider getJavaColorProvider() {
- return fgColorProvider;
- }
-
- /**
- * Returns the singleton document scanner.
- */
- public static RuleBasedScanner getJavaDocScanner() {
- return fgDocScanner;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java deleted file mode 100644 index ff30b90639f..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java +++ /dev/null @@ -1,30 +0,0 @@ -/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-package org.eclipse.ui.examples.javaeditor;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-public class JavaEditorMessages {
-
- private static final String RESOURCE_BUNDLE= "org.eclipse.ui.examples.javaeditor.JavaEditorMessages";//$NON-NLS-1$
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private JavaEditorMessages() {
- }
-
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- }
-
- public static ResourceBundle getResourceBundle() {
- return fgResourceBundle;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties deleted file mode 100644 index 89a655da834..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties +++ /dev/null @@ -1,33 +0,0 @@ -#############################################################
-#
-# (c) Copyright IBM Corp. 2000, 2001.
-# All Rights Reserved.
-#
-#############################################################
-
-## Actions ##
-
-ContentAssistProposal.label=Content Assist@Ctrl+SPACE
-ContentAssistProposal.tooltip=Content Assist
-ContentAssistProposal.image=
-ContentAssistProposal.description=Content Assist
-
-ContentAssistTip.label=Content Tip@Ctrl+SHIFT+SPACE
-ContentAssistTip.tooltip=Content Tip
-ContentAssistTip.image=
-ContentAssistTip.description=Content Tip
-
-TogglePresentation.label=Change Presentation
-TogglePresentation.tooltip=Enable/Disable Segmented Source Viewer
-TogglePresentation.image=togglepresentation.gif
-TogglePresentation.description=Enable/Disable Segmented Source Viewer
-
-OutlinePage.segment.title_pattern=position {0}
-
-AutoIndent.error.bad_location_1=JavaAutoIndentStrategy.getAutoIndentString: BadLocationException
-AutoIndent.error.bad_location_2=JavaAutoIndentStrategy.calcShiftBackReplace: BadLocationException
-
-CompletionProcessor.ContextInfo.display.pattern=proposal {0} at position {1}
-CompletionProcessor.ContextInfo.value.pattern=proposal {0} valid from {1} to {2}
-CompletionProcessor.Proposal.ContextInfo.pattern={0} valid 5 characters around insertion point
-CompletionProcessor.Proposal.hoverinfo.pattern=Java keyword: {0}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java deleted file mode 100644 index 3d46dd102fb..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.List;
-
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.jface.text.DefaultAutoIndentStrategy;
-import org.eclipse.jface.text.IAutoIndentStrategy;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextDoubleClickStrategy;
-import org.eclipse.jface.text.ITextHover;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.presentation.PresentationReconciler;
-import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
-import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.ui.examples.javaeditor.java.JavaAutoIndentStrategy;
-import org.eclipse.ui.examples.javaeditor.java.JavaCompletionProcessor;
-import org.eclipse.ui.examples.javaeditor.java.JavaDoubleClickSelector;
-import org.eclipse.ui.examples.javaeditor.java.JavaPartitionScanner;
-import org.eclipse.ui.examples.javaeditor.javadoc.JavaDocCompletionProcessor;
-import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
-
-/**
- * Example configuration for an <code>SourceViewer</code> which shows Java code.
- */
-public class JavaSourceViewerConfiguration extends SourceViewerConfiguration {
-
-
- /**
- * Single token scanner.
- */
- static class SingleTokenScanner extends BufferedRuleBasedScanner {
- public SingleTokenScanner(TextAttribute attribute) {
- setDefaultReturnToken(new Token(attribute));
- }
- };
-
-
- /**
- * Default constructor.
- */
- public JavaSourceViewerConfiguration() {
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
- return new JavaAnnotationHover();
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
- return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new JavaAutoIndentStrategy() : new DefaultAutoIndentStrategy());
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] { IDocument.DEFAULT_CONTENT_TYPE, JavaPartitionScanner.JAVA_DOC, JavaPartitionScanner.JAVA_MULTILINE_COMMENT };
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
-
- ContentAssistant assistant= new ContentAssistant();
- assistant.setContentAssistProcessor(new JavaCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
- assistant.setContentAssistProcessor(new JavaDocCompletionProcessor(), JavaPartitionScanner.JAVA_DOC);
-
- assistant.enableAutoActivation(true);
- assistant.setAutoActivationDelay(500);
- assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
- assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
- assistant.setContextInformationPopupBackground(JavaEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
-
- return assistant;
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
- return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
- return new JavaDoubleClickSelector();
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
- return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
-
- JavaColorProvider provider= JavaEditorEnvironment.getJavaColorProvider();
- PresentationReconciler reconciler= new PresentationReconciler();
-
- DefaultDamagerRepairer dr= new DefaultDamagerRepairer(JavaEditorEnvironment.getJavaCodeScanner());
- reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
- reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
-
- dr= new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.JAVADOC_DEFAULT))));
- reconciler.setDamager(dr, JavaPartitionScanner.JAVA_DOC);
- reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_DOC);
-
- dr= new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
- reconciler.setDamager(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
- reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
-
- return reconciler;
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public int getTabWidth(ISourceViewer sourceViewer) {
- return 4;
- }
-
- /* (non-Javadoc)
- * Method declared on SourceViewerConfiguration
- */
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
- return new JavaTextHover();
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java deleted file mode 100644 index 78b6a4ac309..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextHover;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Region;
-
-/**
- * Example implementation for an <code>ITextHover</code> which hovers over Java code.
- */
-public class JavaTextHover implements ITextHover {
-
- /* (non-Javadoc)
- * Method declared on ITextHover
- */
- public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
- if (hoverRegion != null) {
- try {
- if (hoverRegion.getLength() > -1)
- return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
- } catch (BadLocationException x) {
- }
- }
- return "empty selection";
- }
-
- /* (non-Javadoc)
- * Method declared on ITextHover
- */
- public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
- Point selection= textViewer.getSelectedRange();
- if (selection.x <= offset && offset < selection.x + selection.y)
- return new Region(selection.x, selection.y);
- return new Region(offset, 0);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java deleted file mode 100644 index 625fbd2919e..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.eclipse.ui.examples.javaeditor;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ResourceBundle;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.TextEditorAction;
-
-/**
- * A toolbar action which toggles the presentation model of the
- * connected text editor. The editor shows either the highlight range
- * only or always the whole document.
- */
-public class PresentationAction extends TextEditorAction {
-
- /**
- * Constructs and updates the action.
- */
- public PresentationAction() {
- super(JavaEditorMessages.getResourceBundle(), "TogglePresentation.", null); //$NON-NLS-1$
- update();
- }
-
- /* (non-Javadoc)
- * Method declared on IAction
- */
- public void run() {
-
- ITextEditor editor= getTextEditor();
-
- editor.resetHighlightRange();
- boolean show= editor.showsHighlightRangeOnly();
- setChecked(!show);
- editor.showHighlightRangeOnly(!show);
- }
-
- /* (non-Javadoc)
- * Method declared on TextEditorAction
- */
- public void update() {
- setChecked(getTextEditor() != null && getTextEditor().showsHighlightRangeOnly());
- setEnabled(true);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java deleted file mode 100644 index d47ab8b2c29..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java +++ /dev/null @@ -1,265 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.java;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultAutoIndentStrategy;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IDocument;
-
-/**
- * Auto indent strategy sensitive to brackets.
- */
-public class JavaAutoIndentStrategy extends DefaultAutoIndentStrategy {
-
- public JavaAutoIndentStrategy() {
- }
-
- /* (non-Javadoc)
- * Method declared on IAutoIndentStrategy
- */
- public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
- if (c.length == 0 && c.text != null && endsWithDelimiter(d, c.text))
- smartIndentAfterNewLine(d, c);
- else if ("}".equals(c.text)) { //$NON-NLS-1$
- smartInsertAfterBracket(d, c);
- }
- }
-
- /**
- * Returns whether or not the text ends with one of the given search strings.
- */
- private boolean endsWithDelimiter(IDocument d, String txt) {
-
- String[] delimiters= d.getLegalLineDelimiters();
-
- for (int i= 0; i < delimiters.length; i++) {
- if (txt.endsWith(delimiters[i]))
- return true;
- }
-
- return false;
- }
-
- /**
- * Returns the line number of the next bracket after end.
- * @returns the line number of the next matching bracket after end
- * @param document - the document being parsed
- * @param line - the line to start searching back from
- * @param end - the end position to search back from
- * @param closingBracketIncrease - the number of brackets to skip
- */
- protected int findMatchingOpenBracket(IDocument document, int line, int end, int closingBracketIncrease) throws BadLocationException {
-
- int start= document.getLineOffset(line);
- int brackcount= getBracketCount(document, start, end, false) - closingBracketIncrease;
-
- // sum up the brackets counts of each line (closing brackets count negative,
- // opening positive) until we find a line the brings the count to zero
- while (brackcount < 0) {
- line--;
- if (line < 0) {
- return -1;
- }
- start= document.getLineOffset(line);
- end= start + document.getLineLength(line) - 1;
- brackcount += getBracketCount(document, start, end, false);
- }
- return line;
- }
-
- /**
- * Returns the bracket value of a section of text. Closing brackets have a value of -1 and
- * open brackets have a value of 1.
- * @returns the line number of the next matching bracket after end
- * @param document - the document being parsed
- * @param start - the start position for the search
- * @param end - the end position for the search
- * @param ignoreCloseBrackets - whether or not to ignore closing brackets in the count
- */
- private int getBracketCount(IDocument document, int start, int end, boolean ignoreCloseBrackets) throws BadLocationException {
-
- int begin = start;
- int bracketcount= 0;
- while (begin < end) {
- char curr= document.getChar(begin);
- begin++;
- switch (curr) {
- case '/' :
- if (begin < end) {
- char next= document.getChar(begin);
- if (next == '*') {
- // a comment starts, advance to the comment end
- begin= getCommentEnd(document, begin + 1, end);
- } else if (next == '/') {
- // '//'-comment: nothing to do anymore on this line
- begin= end;
- }
- }
- break;
- case '*' :
- if (begin < end) {
- char next= document.getChar(begin);
- if (next == '/') {
- // we have been in a comment: forget what we read before
- bracketcount= 0;
- begin++;
- }
- }
- break;
- case '{' :
- bracketcount++;
- ignoreCloseBrackets= false;
- break;
- case '}' :
- if (!ignoreCloseBrackets) {
- bracketcount--;
- }
- break;
- case '"' :
- case '\'' :
- begin= getStringEnd(document, begin, end, curr);
- break;
- default :
- }
- }
- return bracketcount;
- }
-
- /**
- * Returns the end position a comment starting at pos.
- * @returns the end position a comment starting at pos
- * @param document - the document being parsed
- * @param position - the start position for the search
- * @param end - the end position for the search
- */
- private int getCommentEnd(IDocument document, int position, int end) throws BadLocationException {
- int currentPosition = position;
- while (currentPosition < end) {
- char curr= document.getChar(currentPosition);
- currentPosition++;
- if (curr == '*') {
- if (currentPosition < end && document.getChar(currentPosition) == '/') {
- return currentPosition + 1;
- }
- }
- }
- return end;
- }
-
- /**
- * Returns the String at line with the leading whitespace removed.
- * @returns the String at line with the leading whitespace removed.
- * @param document - the document being parsed
- * @param line - the line being searched
- */
- protected String getIndentOfLine(IDocument document, int line) throws BadLocationException {
- if (line > -1) {
- int start= document.getLineOffset(line);
- int end= start + document.getLineLength(line) - 1;
- int whiteend= findEndOfWhiteSpace(document, start, end);
- return document.get(start, whiteend - start);
- } else {
- return ""; //$NON-NLS-1$
- }
- }
-
- /**
- * Returns the position of the character in the document after position.
- * @returns the next location of character.
- * @param document - the document being parsed
- * @param position - the position to start searching from
- * @param end - the end of the document
- * @param character - the character you are trying to match
- */
- private int getStringEnd(IDocument document, int position, int end, char character) throws BadLocationException {
- int currentPosition = position;
- while (currentPosition < end) {
- char currentCharacter= document.getChar(currentPosition);
- currentPosition++;
- if (currentCharacter == '\\') {
- // ignore escaped characters
- currentPosition++;
- } else if (currentCharacter == character) {
- return currentPosition;
- }
- }
- return end;
- }
-
- /**
- * Set the indent of a new line based on the command provided in the supplied document.
- * @param document - the document being parsed
- * @param command - the command being performed
- */
- protected void smartIndentAfterNewLine(IDocument document, DocumentCommand command) {
-
- int docLength= document.getLength();
- if (command.offset == -1 || docLength == 0)
- return;
-
- try {
- int p= (command.offset == docLength ? command.offset - 1 : command.offset);
- int line= document.getLineOfOffset(p);
-
- StringBuffer buf= new StringBuffer(command.text);
- if (command.offset < docLength && document.getChar(command.offset) == '}') {
- int indLine= findMatchingOpenBracket(document, line, command.offset, 0);
- if (indLine == -1) {
- indLine= line;
- }
- buf.append(getIndentOfLine(document, indLine));
- } else {
- int start= document.getLineOffset(line);
- int whiteend= findEndOfWhiteSpace(document, start, command.offset);
- buf.append(document.get(start, whiteend - start));
- if (getBracketCount(document, start, command.offset, true) > 0) {
- buf.append('\t');
- }
- }
- command.text= buf.toString();
-
- } catch (BadLocationException excp) {
- System.out.println(JavaEditorMessages.getString("AutoIndent.error.bad_location_1")); //$NON-NLS-1$
- }
- }
-
- /**
- * Set the indent of a bracket based on the command provided in the supplied document.
- * @param document - the document being parsed
- * @param command - the command being performed
- */
- protected void smartInsertAfterBracket(IDocument document, DocumentCommand command) {
- if (command.offset == -1 || document.getLength() == 0)
- return;
-
- try {
- int p= (command.offset == document.getLength() ? command.offset - 1 : command.offset);
- int line= document.getLineOfOffset(p);
- int start= document.getLineOffset(line);
- int whiteend= findEndOfWhiteSpace(document, start, command.offset);
-
- // shift only when line does not contain any text up to the closing bracket
- if (whiteend == command.offset) {
- // evaluate the line with the opening bracket that matches out closing bracket
- int indLine= findMatchingOpenBracket(document, line, command.offset, 1);
- if (indLine != -1 && indLine != line) {
- // take the indent of the found line
- StringBuffer replaceText= new StringBuffer(getIndentOfLine(document, indLine));
- // add the rest of the current line including the just added close bracket
- replaceText.append(document.get(whiteend, command.offset - whiteend));
- replaceText.append(command.text);
- // modify document command
- command.length= command.offset - start;
- command.offset= start;
- command.text= replaceText.toString();
- }
- }
- } catch (BadLocationException excp) {
- System.out.println(JavaEditorMessages.getString("AutoIndent.error.bad_location_2")); //$NON-NLS-1$
- }
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java deleted file mode 100644 index fe88175eb2f..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.java;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.rules.EndOfLineRule;
-import org.eclipse.jface.text.rules.IRule;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.jface.text.rules.SingleLineRule;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WhitespaceRule;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
-import org.eclipse.ui.examples.javaeditor.util.JavaWhitespaceDetector;
-import org.eclipse.ui.examples.javaeditor.util.JavaWordDetector;
-
-/**
- * A Java code scanner.
- */
-public class JavaCodeScanner extends RuleBasedScanner {
-
- private static String[] fgKeywords= { "abstract", "break", "case", "catch", "class", "continue", "default", "do", "else", "extends", "final", "finally", "for", "if", "implements", "import", "instanceof", "interface", "native", "new", "package", "private", "protected", "public", "return", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "volatile", "while" }; //$NON-NLS-36$ //$NON-NLS-35$ //$NON-NLS-34$ //$NON-NLS-33$ //$NON-NLS-32$ //$NON-NLS-31$ //$NON-NLS-30$ //$NON-NLS-29$ //$NON-NLS-28$ //$NON-NLS-27$ //$NON-NLS-26$ //$NON-NLS-25$ //$NON-NLS-24$ //$NON-NLS-23$ //$NON-NLS-22$ //$NON-NLS-21$ //$NON-NLS-20$ //$NON-NLS-19$ //$NON-NLS-18$ //$NON-NLS-17$ //$NON-NLS-16$ //$NON-NLS-15$ //$NON-NLS-14$ //$NON-NLS-13$ //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
-
- private static String[] fgTypes= { "void", "boolean", "char", "byte", "short", "int", "long", "float", "double" }; //$NON-NLS-1$ //$NON-NLS-5$ //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-2$
-
- private static String[] fgConstants= { "false", "null", "true" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
-
- private TextAttribute fComment;
- private TextAttribute fKeyword;
- private TextAttribute fType;
- private TextAttribute fString;
- private JavaColorProvider fColorProvider;
-
- /**
- * Creates a Java code scanner
- */
- public JavaCodeScanner(JavaColorProvider provider) {
-
- IToken keyword= new Token(new TextAttribute(provider.getColor(JavaColorProvider.KEYWORD)));
- IToken type= new Token(new TextAttribute(provider.getColor(JavaColorProvider.TYPE)));
- IToken string= new Token(new TextAttribute(provider.getColor(JavaColorProvider.STRING)));
- IToken comment= new Token(new TextAttribute(provider.getColor(JavaColorProvider.SINGLE_LINE_COMMENT)));
- IToken other= new Token(new TextAttribute(provider.getColor(JavaColorProvider.DEFAULT)));
-
- List rules= new ArrayList();
-
- // Add rule for single line comments.
- rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
-
- // Add rule for strings and character constants.
- rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
- rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-
- // Add generic whitespace rule.
- rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
-
- // Add word rule for keywords, types, and constants.
- WordRule wordRule= new WordRule(new JavaWordDetector(), other);
- for (int i= 0; i < fgKeywords.length; i++)
- wordRule.addWord(fgKeywords[i], keyword);
- for (int i= 0; i < fgTypes.length; i++)
- wordRule.addWord(fgTypes[i], type);
- for (int i= 0; i < fgConstants.length; i++)
- wordRule.addWord(fgConstants[i], type);
- rules.add(wordRule);
-
- IRule[] result= new IRule[rules.size()];
- rules.toArray(result);
- setRules(result);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java deleted file mode 100644 index 8b9d5eb739d..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.java;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.text.MessageFormat;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
-import org.eclipse.jface.text.contentassist.ContextInformation;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-
-/**
- * Example Java completion processor.
- */
-public class JavaCompletionProcessor implements IContentAssistProcessor {
-
- /**
- * Simple content assist tip closer. The tip is valid in a range
- * of 5 characters around its popup location.
- */
- protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
-
- protected int fInstallOffset;
-
- /*
- * @see IContextInformationValidator#isContextInformationValid(int)
- */
- public boolean isContextInformationValid(int offset) {
- return Math.abs(fInstallOffset - offset) < 5;
- }
-
- /*
- * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
- */
- public void install(IContextInformation info, ITextViewer viewer, int offset) {
- fInstallOffset= offset;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
- */
- public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
- return false;
- }
- };
-
- protected final static String[] fgProposals=
- { "abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "continue", "default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while" }; //$NON-NLS-48$ //$NON-NLS-47$ //$NON-NLS-46$ //$NON-NLS-45$ //$NON-NLS-44$ //$NON-NLS-43$ //$NON-NLS-42$ //$NON-NLS-41$ //$NON-NLS-40$ //$NON-NLS-39$ //$NON-NLS-38$ //$NON-NLS-37$ //$NON-NLS-36$ //$NON-NLS-35$ //$NON-NLS-34$ //$NON-NLS-33$ //$NON-NLS-32$ //$NON-NLS-31$ //$NON-NLS-30$ //$NON-NLS-29$ //$NON-NLS-28$ //$NON-NLS-27$ //$NON-NLS-26$ //$NON-NLS-25$ //$NON-NLS-24$ //$NON-NLS-23$ //$NON-NLS-22$ //$NON-NLS-21$ //$NON-NLS-20$ //$NON-NLS-19$ //$NON-NLS-18$ //$NON-NLS-17$ //$NON-NLS-16$ //$NON-NLS-15$ //$NON-NLS-14$ //$NON-NLS-13$ //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
-
- protected IContextInformationValidator fValidator= new Validator();
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
- ICompletionProposal[] result= new ICompletionProposal[fgProposals.length];
- for (int i= 0; i < fgProposals.length; i++) {
- IContextInformation info= new ContextInformation(fgProposals[i], MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
- result[i]= new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i]})); //$NON-NLS-1$
- }
- return result;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- IContextInformation[] result= new IContextInformation[5];
- for (int i= 0; i < result.length; i++)
- result[i]= new ContextInformation(
- MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset) }), //$NON-NLS-1$
- MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)})); //$NON-NLS-1$
- return result;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- return new char[] { '.', '(' };
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public char[] getContextInformationAutoActivationCharacters() {
- return new char[] { '#' };
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public IContextInformationValidator getContextInformationValidator() {
- return fValidator;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public String getErrorMessage() {
- return null;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java deleted file mode 100644 index be1ea743b21..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java +++ /dev/null @@ -1,234 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.java;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextDoubleClickStrategy;
-import org.eclipse.jface.text.ITextViewer;
-
-/**
- * Double click strategy aware of Java identifier syntax rules.
- */
-public class JavaDoubleClickSelector implements ITextDoubleClickStrategy {
-
- protected ITextViewer fText;
- protected int fPos;
- protected int fStartPos;
- protected int fEndPos;
-
- protected static char[] fgBrackets= { '{', '}', '(', ')', '[', ']', '"', '"' };
-
- /*
- * Create a JavaDoubleClickSelector.
- */
- public JavaDoubleClickSelector() {
- super();
- }
-
- /* (non-Javadoc)
- * Method declared on ITextDoubleClickStrategy
- */
- public void doubleClicked(ITextViewer text) {
-
- fPos= text.getSelectedRange().x;
-
- if (fPos < 0)
- return;
-
- fText= text;
-
- if (!selectBracketBlock())
- selectWord();
- }
-
- /**
- * Match the brackets at the current selection. Return true if successful,
- * false otherwise.
- */
- protected boolean matchBracketsAt() {
-
- char prevChar, nextChar;
-
- int i;
- int bracketIndex1= fgBrackets.length;
- int bracketIndex2= fgBrackets.length;
-
- fStartPos= -1;
- fEndPos= -1;
-
- // get the chars preceding and following the start position
- try {
-
- IDocument doc= fText.getDocument();
-
- prevChar= doc.getChar(fPos - 1);
- nextChar= doc.getChar(fPos);
-
- // is the char either an open or close bracket?
- for (i= 0; i < fgBrackets.length; i= i + 2) {
- if (prevChar == fgBrackets[i]) {
- fStartPos= fPos - 1;
- bracketIndex1= i;
- }
- }
- for (i= 1; i < fgBrackets.length; i= i + 2) {
- if (nextChar == fgBrackets[i]) {
- fEndPos= fPos;
- bracketIndex2= i;
- }
- }
-
- if (fStartPos > -1 && bracketIndex1 < bracketIndex2) {
- fEndPos= searchForClosingBracket(fStartPos, prevChar, fgBrackets[bracketIndex1 + 1], doc);
- if (fEndPos > -1)
- return true;
- else
- fStartPos= -1;
- } else if (fEndPos > -1) {
- fStartPos= searchForOpenBracket(fEndPos, fgBrackets[bracketIndex2 - 1], nextChar, doc);
- if (fStartPos > -1)
- return true;
- else
- fEndPos= -1;
- }
-
- } catch (BadLocationException x) {
- }
-
- return false;
- }
-
- /**
- * Select the word at the current selection. Return true if successful,
- * false otherwise.
- */
- protected boolean matchWord() {
-
- IDocument doc= fText.getDocument();
-
- try {
-
- int pos= fPos;
- char c;
-
- while (pos >= 0) {
- c= doc.getChar(pos);
- if (!Character.isJavaIdentifierPart(c))
- break;
- --pos;
- }
-
- fStartPos= pos;
-
- pos= fPos;
- int length= doc.getLength();
-
- while (pos < length) {
- c= doc.getChar(pos);
- if (!Character.isJavaIdentifierPart(c))
- break;
- ++pos;
- }
-
- fEndPos= pos;
-
- return true;
-
- } catch (BadLocationException x) {
- }
-
- return false;
- }
-
- /**
- * Returns the position of the closing bracket after startPosition.
- * @returns the location of the closing bracket.
- * @param startPosition - the beginning position
- * @param openBracket - the character that represents the open bracket
- * @param closeBracket - the character that represents the close bracket
- * @param document - the document being searched
- */
- protected int searchForClosingBracket(int startPosition, char openBracket, char closeBracket, IDocument document) throws BadLocationException {
- int stack= 1;
- int closePosition= startPosition + 1;
- int length= document.getLength();
- char nextChar;
-
- while (closePosition < length && stack > 0) {
- nextChar= document.getChar(closePosition);
- if (nextChar == openBracket && nextChar != closeBracket)
- stack++;
- else if (nextChar == closeBracket)
- stack--;
- closePosition++;
- }
-
- if (stack == 0)
- return closePosition - 1;
- else
- return -1;
-
- }
-
- /**
- * Returns the position of the open bracket before startPosition.
- * @returns the location of the starting bracket.
- * @param startPosition - the beginning position
- * @param openBracket - the character that represents the open bracket
- * @param closeBracket - the character that represents the close bracket
- * @param document - the document being searched
- */
- protected int searchForOpenBracket(int startPosition, char openBracket, char closeBracket, IDocument document) throws BadLocationException {
- int stack= 1;
- int openPos= startPosition - 1;
- char nextChar;
-
- while (openPos >= 0 && stack > 0) {
- nextChar= document.getChar(openPos);
- if (nextChar == closeBracket && nextChar != openBracket)
- stack++;
- else if (nextChar == openBracket)
- stack--;
- openPos--;
- }
-
- if (stack == 0)
- return openPos + 1;
- else
- return -1;
- }
-
- /**
- * Select the area between the selected bracket and the closing bracket. Return
- * true if successful.
- */
- protected boolean selectBracketBlock() {
- if (matchBracketsAt()) {
-
- if (fStartPos == fEndPos)
- fText.setSelectedRange(fStartPos, 0);
- else
- fText.setSelectedRange(fStartPos + 1, fEndPos - fStartPos - 1);
-
- return true;
- }
- return false;
- }
-
- /**
- * Select the word at the current selection.
- */
- protected void selectWord() {
- if (matchWord()) {
-
- if (fStartPos == fEndPos)
- fText.setSelectedRange(fStartPos, 0);
- else
- fText.setSelectedRange(fStartPos + 1, fEndPos - fStartPos - 1);
- }
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java deleted file mode 100644 index 85984c6e937..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java +++ /dev/null @@ -1,26 +0,0 @@ -/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-package org.eclipse.ui.examples.javaeditor.java;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-public class JavaEditorMessages {
-
- private static final String RESOURCE_BUNDLE= "org.eclipse.ui.examples.javaeditor.JavaEditorMessages";//$NON-NLS-1$
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private JavaEditorMessages() {
- }
-
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java deleted file mode 100644 index 291e31fca81..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.java;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jface.text.rules.EndOfLineRule;
-import org.eclipse.jface.text.rules.ICharacterScanner;
-import org.eclipse.jface.text.rules.IPredicateRule;
-import org.eclipse.jface.text.rules.IRule;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.MultiLineRule;
-import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.jface.text.rules.SingleLineRule;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WordRule;
-
-/**
- * This scanner recognizes the JavaDoc comments and Java multi line comments.
- */
-public class JavaPartitionScanner extends RuleBasedPartitionScanner {
-
- private final static String SKIP= "__skip"; //$NON-NLS-1$
- public final static String JAVA_MULTILINE_COMMENT= "__java_multiline_comment"; //$NON-NLS-1$
- public final static String JAVA_DOC= "__java_javadoc"; //$NON-NLS-1$
-
- /**
- * Detector for empty comments.
- */
- static class EmptyCommentDetector implements IWordDetector {
-
- /* (non-Javadoc)
- * Method declared on IWordDetector
- */
- public boolean isWordStart(char c) {
- return (c == '/');
- }
-
- /* (non-Javadoc)
- * Method declared on IWordDetector
- */
- public boolean isWordPart(char c) {
- return (c == '*' || c == '/');
- }
- };
-
- /**
- *
- */
- static class WordPredicateRule extends WordRule implements IPredicateRule {
-
- private IToken fSuccessToken;
-
- public WordPredicateRule(IToken successToken) {
- super(new EmptyCommentDetector());
- fSuccessToken= successToken;
- addWord("/**/", fSuccessToken);
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean)
- */
- public IToken evaluate(ICharacterScanner scanner, boolean resume) {
- return super.evaluate(scanner);
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken()
- */
- public IToken getSuccessToken() {
- return fSuccessToken;
- }
- };
-
- /**
- * Creates the partitioner and sets up the appropriate rules.
- */
- public JavaPartitionScanner() {
- super();
-
- IToken javaDoc= new Token(JAVA_DOC);
- IToken comment= new Token(JAVA_MULTILINE_COMMENT);
-
- List rules= new ArrayList();
-
- // Add rule for single line comments.
- rules.add(new EndOfLineRule("//", Token.UNDEFINED)); //$NON-NLS-1$
-
- // Add rule for strings and character constants.
- rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
- rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-
- // Add special case word rule.
- rules.add(new WordPredicateRule(comment));
-
- // Add rules for multi-line comments and javadoc.
- rules.add(new MultiLineRule("/**", "*/", javaDoc)); //$NON-NLS-1$ //$NON-NLS-2$
- rules.add(new MultiLineRule("/*", "*/", comment)); //$NON-NLS-1$ //$NON-NLS-2$
-
- IPredicateRule[] result= new IPredicateRule[rules.size()];
- rules.toArray(result);
- setPredicateRules(result);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java deleted file mode 100644 index b9994084f23..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.javadoc;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-
-/**
- * Example Java doc completion processor.
- */
-public class JavaDocCompletionProcessor implements IContentAssistProcessor {
-
- protected final static String[] fgProposals= { "@author", "@deprecated", "@exception", "@param", "@return", "@see", "@serial", "@serialData", "@serialField", "@since", "@throws", "@version" }; //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-7$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
- ICompletionProposal[] result= new ICompletionProposal[fgProposals.length];
- for (int i= 0; i < fgProposals.length; i++)
- result[i]= new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length());
- return result;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- return null;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- return null;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public char[] getContextInformationAutoActivationCharacters() {
- return null;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public IContextInformationValidator getContextInformationValidator() {
- return null;
- }
-
- /* (non-Javadoc)
- * Method declared on IContentAssistProcessor
- */
- public String getErrorMessage() {
- return null;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java deleted file mode 100644 index 55dc5699280..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.javadoc;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.rules.IRule;
-import org.eclipse.jface.text.rules.IToken;
-import org.eclipse.jface.text.rules.IWordDetector;
-import org.eclipse.jface.text.rules.RuleBasedScanner;
-import org.eclipse.jface.text.rules.SingleLineRule;
-import org.eclipse.jface.text.rules.Token;
-import org.eclipse.jface.text.rules.WhitespaceRule;
-import org.eclipse.jface.text.rules.WordRule;
-import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
-import org.eclipse.ui.examples.javaeditor.util.JavaWhitespaceDetector;
-
-/**
- * A rule based JavaDoc scanner.
- */
-public class JavaDocScanner extends RuleBasedScanner {
-
- /**
- * A key word detector.
- */
- static class JavaDocWordDetector implements IWordDetector {
-
- /* (non-Javadoc)
- * Method declared on IWordDetector
- */
- public boolean isWordStart(char c) {
- return (c == '@');
- }
-
- /* (non-Javadoc)
- * Method declared on IWordDetector
- */
- public boolean isWordPart(char c) {
- return Character.isLetter(c);
- }
- };
-
- private static String[] fgKeywords= { "@author", "@deprecated", "@exception", "@param", "@return", "@see", "@serial", "@serialData", "@serialField", "@since", "@throws", "@version" }; //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-7$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
-
- /**
- * Create a new java doc scanner.
- */
- public JavaDocScanner(JavaColorProvider provider) {
- super();
-
- IToken keyword= new Token(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_KEYWORD)));
- IToken tag= new Token(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_TAG)));
- IToken link= new Token(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_LINK)));
-
- List list= new ArrayList();
-
- // Add rule for tags.
- list.add(new SingleLineRule("<", ">", tag)); //$NON-NLS-2$ //$NON-NLS-1$
-
- // Add rule for links.
- list.add(new SingleLineRule("{", "}", link)); //$NON-NLS-2$ //$NON-NLS-1$
-
- // Add generic whitespace rule.
- list.add(new WhitespaceRule(new JavaWhitespaceDetector()));
-
- // Add word rule for keywords.
- WordRule wordRule= new WordRule(new JavaDocWordDetector());
- for (int i= 0; i < fgKeywords.length; i++)
- wordRule.addWord(fgKeywords[i], keyword);
- list.add(wordRule);
-
- IRule[] result= new IRule[list.size()];
- list.toArray(result);
- setRules(result);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif Binary files differdeleted file mode 100644 index a0831f04bc6..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif +++ /dev/null diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java deleted file mode 100644 index 35c786bc815..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.util;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Manager for colors used in the Java editor
- */
-public class JavaColorProvider {
-
- public static final RGB MULTI_LINE_COMMENT= new RGB(128, 0, 0);
- public static final RGB SINGLE_LINE_COMMENT= new RGB(128, 128, 0);
- public static final RGB KEYWORD= new RGB(0, 0, 128);
- public static final RGB TYPE= new RGB(0, 0, 128);
- public static final RGB STRING= new RGB(0, 128, 0);
- public static final RGB DEFAULT= new RGB(0, 0, 0);
- public static final RGB JAVADOC_KEYWORD= new RGB(0, 128, 0);
- public static final RGB JAVADOC_TAG= new RGB(128, 128, 128);
- public static final RGB JAVADOC_LINK= new RGB(128, 128, 128);
- public static final RGB JAVADOC_DEFAULT= new RGB(0, 128, 128);
-
- protected Map fColorTable= new HashMap(10);
-
- /**
- * Release all of the color resources held onto by the receiver.
- */
- public void dispose() {
- Iterator e= fColorTable.values().iterator();
- while (e.hasNext())
- ((Color) e.next()).dispose();
- }
-
- /**
- * Return the Color that is stored in the Color table as rgb.
- */
- public Color getColor(RGB rgb) {
- Color color= (Color) fColorTable.get(rgb);
- if (color == null) {
- color= new Color(Display.getCurrent(), rgb);
- fColorTable.put(rgb, color);
- }
- return color;
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java deleted file mode 100644 index a14a0eb40c0..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.util;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.rules.IWhitespaceDetector;
-
-/**
- * A java aware white space detector.
- */
-public class JavaWhitespaceDetector implements IWhitespaceDetector {
-
- /* (non-Javadoc)
- * Method declared on IWhitespaceDetector
- */
- public boolean isWhitespace(char character) {
- return Character.isWhitespace(character);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java deleted file mode 100644 index 56126049274..00000000000 --- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.eclipse.ui.examples.javaeditor.util;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.text.rules.IWordDetector;
-
-/**
- * A Java aware word detector.
- */
-public class JavaWordDetector implements IWordDetector {
-
- /* (non-Javadoc)
- * Method declared on IWordDetector.
- */
- public boolean isWordPart(char character) {
- return Character.isJavaIdentifierPart(character);
- }
-
- /* (non-Javadoc)
- * Method declared on IWordDetector.
- */
- public boolean isWordStart(char character) {
- return Character.isJavaIdentifierStart(character);
- }
-}
diff --git a/org.eclipse.ui.examples.javaeditor/about.html b/org.eclipse.ui.examples.javaeditor/about.html deleted file mode 100644 index 9db411aab99..00000000000 --- a/org.eclipse.ui.examples.javaeditor/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 ("Content"). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the -Common Public License Version 1.0 ("CPL"). 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, "Program" 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 ("Other License"), any modifications, enhancements and/or -other code and/or documentation ("Modifications") 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.ui.examples.javaeditor/build.properties b/org.eclipse.ui.examples.javaeditor/build.properties deleted file mode 100644 index d1dda4adbd7..00000000000 --- a/org.eclipse.ui.examples.javaeditor/build.properties +++ /dev/null @@ -1,11 +0,0 @@ -source.javaeditorexample.jar = Eclipse Java Editor Example/
-
-bin.includes = doc-html/,\
- icons/,\
- .options,\
- about.html,\
- plugin.properties,\
- plugin.xml,\
- *.jar
-
-src.includes = about.html
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm b/org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm deleted file mode 100644 index b071dbdf45b..00000000000 --- a/org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm +++ /dev/null @@ -1,14 +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="GENERATOR" content="Mozilla/4.73 [en] (Win98; U) [Netscape]">
- <title>Legal Notices</title>
-</head>
-<body>
-
-<h3>
-<a NAME="Notices"></a>Notices</h3>
-(c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
-</body>
-</html>
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm b/org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm deleted file mode 100644 index e1aabb63d6a..00000000000 --- a/org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm +++ /dev/null @@ -1,13 +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">
- <title>Legal Notices</title>
-</head>
-<body>
-
-<h3>
-<a NAME="Notices"></a>Notices</h3>
-(c) Copyright IBM Corp. and others 2000, 2002. All Rights Reserved.
-</body>
-</html>
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif b/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif Binary files differdeleted file mode 100644 index 360f8e99891..00000000000 --- a/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif +++ /dev/null diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gif b/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gif Binary files differdeleted file mode 100644 index 61cef485216..00000000000 --- a/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gif +++ /dev/null diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html b/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html deleted file mode 100644 index 81042c28919..00000000000 --- a/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html +++ /dev/null @@ -1,236 +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="GENERATOR" content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]">
- <title>Desktop - Java Editor Example</title>
-</head>
-<body>
-
-<h2>
-<b>Example - Java Editor</b></h2>
-
-<h3>
-Introduction</h3>
-The Java Editor example demonstrates the standard features available for
-custom text editors. It also shows how to register an editor
-for a file extension (in this case .jav) and how to define a custom Document
-provider for use by that editor. This example is only for demonstration
-purposes. Java editing support is provided by the Eclipse Java Tooling.
-<h3>
-<b>Features demonstrated in the example editor</b></h3>
-
-<ul>
-<li>
-syntax highlighting</li>
-
-<li>
-content type sensitive content assist (JavaDoc and Java code)</li>
-
-<li>
-communication between content outliner and editor, i.e. content outliner
-selection feeds the highlight range of the editor</li>
-
-<li>
-two different presentation modes</li>
-
-<ul>
-<li>
- marking the highlight range using a visual range indicator</li>
-
-<li>
-confining the editor to show only text within the highlight range (e.g.
-show a single method of a Java class)</li>
-</ul>
-
-<li>
-marker handling</li>
-
-<li>
-document sharing</li>
-</ul>
-
-<h3>
-Features not demonstrated</h3>
-
-<ul>
-<li>
-content formatting</li>
-
-<li>
-dynamic reconciling of content outline page</li>
-</ul>
-
-<h3>
-Running the example editor</h3>
-
-<ol>
-<li>
-Create a project</li>
-
-<li>
-Create a file with the file extension ".jav" in the newly created project.
-The Java example editor opens automatically.</li>
-
-<li>
-Insert Java code. The Java code is dynamically colored. The example editor
-presents the following language elements in different colors: multi-line
-comments, single line comments, Java language reserved words, string and
-character constants, regular Java code, as well as multi-line comments
-following the JavaDoc guidelines. Inside those JavaDoc comments, JavaDoc
-keywords and tags are differently colored.</li>
-
-<li>
-Open a new Java multi-line comment by inserting "/*" outside a Java comment.
-All the text between the inserted "/*" and the first occurrence of "*/"
-or the end of the text changes its color to red. Append another "*". The
-red range changes color to green as the regular multi-line comment now
-is considered containing JavaDoc. Invoke code assist using CTRL-SPACE.
-The function of content assist is to support the user in writing code.
-So on invocation, content assist should list all possible valid completions
-at the invocation location. Inside JavaDoc, the example editor always proposes
-all JavaDoc keywords.</li>
-
-<li>
-Outside a Java comment invoke content tip using CTRL+SHIFT+SPACE. Five
-proposals are listed. Select one and press ENTER. A small floating red
-window appears above the current line displaying the selected proposal.
-The anticipated use of content tips is to let the user express her intention,
-e.g. to enter a method call and to present contextual information which
-guides the user by doing so. In the example editor, the proposal is considered
-valid five characters around the initial invocation location. While the
-content tip is visible, invoke content assist using CTRL+SPACE. Content
-assist invoked in this situation should help the user to accomplish her
-stated intention visible in the content tip. Inside regular Java code,
-the example editor always proposes all Java keywords.</li>
-
-<li>
-Save the Java code. Saving updates the content outliner. The content outliner
-contains ten entries each of them representing one of ten equally sized
-segments of the Java code in the editor. This style of content outline
-has been chosen to show that the semantics of highlight ranges can arbitrarily
-be defined. (See next steps.)</li>
-
-<li>
-Select one of the entries in the content outliner. The corresponding lines
-are marked with a blue bar in the editor's left vertical ruler.</li>
-
-<li>
-Now switch to the segmented presentation mode of the Java editor. For that
-make sure that the editor has the focus and press that button in the desktop's
-toolbar whose hover help says "Enable/Disable segmented source viewer".
-This functionality is anticipated to be used, e.g., for single method views.</li>
-
-<li>
-Select a different entry in the content outliner. Now the editor only shows
-the selected segment. By deselecting the entry in the content outliner,
-the complete Java code is shown again.</li>
-
-<li>
-Select an entry in the content outliner, select a fraction of the visible
-text, and add a task for the selection. The task shows up in the task list.
-Modify the visible code. In the task list, select the previously created
-task and press the "Go to file" button. The task is selected in the visible
-area, correctly taking the previously applied modifications into account.</li>
-
-<li>
-Select another entry in the content outliner. Reveal the previously added
-task from the task list. The editor's highlight range is automatically
-enlarged to enclose the range of the revealed task.</li>
-
-<li>
-Open a new workspace. In the new workspace, open a Java editor for the
-same file as in the original workspace. Modify the editor content. Switch
-back to the original workspace. The editor shows the changes made in the
-other workspace. The two editors showing the same file are lively linked.</li>
-</ol>
-
-<h3>
-Principles for creating custom text editors</h3>
-The following steps are usually necessary do develop a custom text editor.
-<ol>
-<li>
-Create a document provider. A document provider (see IDocumentProvider)
-produces and manages documents (see IDocument) containing a textual representation
-of editor input elements. It is important to decide how the translation
-between element and textual representation looks like and whether the document
-provider should be shared between multiple editors or not. See the class
-FileDocumentProvider in the Java example editor.</li>
-
-<li>
-Create a document partitioner. A document partitioner (see IDocumentPartitioner)
-divides a document into disjoint regions. The partitioner assigns each
-region one content type out of a set of content types predefined by the
-partitioner. On each document change the document's partitioning must be
-updated. See the class JavaPartitioner in the Java example editor. The
-JavaPartitioner determines regions of the types multi-line comments, JavaDoc
-comments, and everything else. It must be ensured that the document provider
-is set on each document produced by the document provider.</li>
-
-<li>
-Determine which of the source viewer plugins should be provided. Among
-other supported plugins are auto indent strategies, double click strategies,
-content formatter, and text presentation reconciler. The subsequent description
-will be restricted to the text presentation reconciler (see IPresentationReconciler).
-In the Java example editor, the text presentation reconciler is utilized
-to implement syntax highlighting.</li>
-
-<li>
-Create for all source viewer plugins the appropriate extensions for each
-supported content type. As seen above, the document partitioner defines
-the supported content types. The default implementation of IPresentationReconciler
-supports IPresentationDamagers and IPresentationRepairers as extensions.
-Those extensions are considered being specific for a particular content
-type. Thus, for a custom editor, the user must first select a subset of
-the supported content types. Regions of a type being a member of the selected
-subset will, e.g., be syntax highlighted. For each of those types the extensions
-must be implemented. See JavaDamagerRepairer and JavaDocDamagerRepairer
-in the example editor.</li>
-
-<li>
-Build a source viewer configuration using the previously created plugins
-and extensions. See JavaSourceViewerConfiguration in the example editor.</li>
-
-<li>
-Customize the class TextEditor or AbstractTextEditor with the developed
-document partitioner and source viewer configuration. Add or replace actions
-and adapt the construction of the editor's context menu. In the actual
-version, this customization must be done in a subclass. See JavaEditor
-in the example editor.</li>
-
-<li>
-Set up an appropriate action bar contributor who contributes editor-related
-actions to the desktop's toolbar and menus. See JavaActionContributor in
-the example editor.</li>
-
-<li>
-Extend the XML configuration file of the editor's plugin, so that the editor
-registers at the predefined editor extension point for a specific set of
-file extensions. Also set up the action bar contributor in the XML file.
-See plugin.xml of this example.</li>
-</ol>
-
-<h3>
-Code organization of the example</h3>
-The example code is organized in four packages:
-<ul>
-<li>
-<tt>org.eclipse.ui.examples.javaeditor </tt>contains all the editor specific
-classes.</li>
-
-<li>
-<tt>org.eclipse.ui.examples.javaeditor.java</tt> contains all Java specific
-source viewer plugins such as the JavaDamagerRepairer as well as the Java
-specific document partitioner.</li>
-
-<li>
-<tt>org.eclipse.ui.examples.javaeditor.javadoc </tt>contains all JavaDoc
-specific source viewer plugins such as the JavaDocDamagerRepairer.</li>
-
-<br><tt>org.eclipse.ui.examples.javaeditor.util</tt> contains convenience
-classes shared by the three other packages.</ul>
-
-<br>
-<p><a href="hglegal2002.htm"><img SRC="ngibmcpy2002.gif" ALT="Copyright IBM Corp. 2000, 2001. All Rights Reserved." BORDER=0 height=14 width=324></a>
-</body>
-</html>
diff --git a/org.eclipse.ui.examples.javaeditor/icons/obj16/java.gif b/org.eclipse.ui.examples.javaeditor/icons/obj16/java.gif Binary files differdeleted file mode 100644 index 83de817b719..00000000000 --- a/org.eclipse.ui.examples.javaeditor/icons/obj16/java.gif +++ /dev/null diff --git a/org.eclipse.ui.examples.javaeditor/plugin.properties b/org.eclipse.ui.examples.javaeditor/plugin.properties deleted file mode 100644 index c79a9476101..00000000000 --- a/org.eclipse.ui.examples.javaeditor/plugin.properties +++ /dev/null @@ -1,15 +0,0 @@ -#########################################
-# (c) Copyright IBM Corp. 2000, 2001.
-# All Rights Reserved.
-#########################################
-#
-# Resource strings for Java Example Editor
-#
-pluginName=JFace Text Example
-providerName = Eclipse.org
-
-#
-# Extension point names
-#
-javaEditorName=Example Java Editor
-javaFileExtension=jav
diff --git a/org.eclipse.ui.examples.javaeditor/plugin.xml b/org.eclipse.ui.examples.javaeditor/plugin.xml deleted file mode 100644 index 788644c278a..00000000000 --- a/org.eclipse.ui.examples.javaeditor/plugin.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<!-- File written by PDE 1.0 -->
-<plugin
- id="org.eclipse.ui.examples.javaeditor"
- name="%pluginName"
- version="2.1.0"
- provider-name="%providerName">
-<requires>
- <import plugin="org.eclipse.ui"/>
- <import plugin="org.eclipse.core.resources"/>
-</requires>
-
-<runtime>
- <library name="javaeditorexample.jar">
- <export name="*"/>
- </library>
-</runtime>
-
-<extension
- point="org.eclipse.ui.editors">
- <editor
- name="%javaEditorName"
- icon="icons/obj16/java.gif"
- extensions="jav"
- contributorClass="org.eclipse.ui.examples.javaeditor.JavaActionContributor"
- class="org.eclipse.ui.examples.javaeditor.JavaEditor"
- id="org.eclipse.ui.JavaEditor">
- </editor>
-</extension>
-
-<extension
- point="org.eclipse.ui.documentProviders">
- <provider
- extensions="%javaFileExtension"
- class="org.eclipse.ui.examples.javaeditor.JavaDocumentProvider"
- id="org.eclipse.ui.examples.javaeditor.JavaDocumentProvider">
- </provider>
-</extension>
-
-</plugin>
diff --git a/org.eclipse.ui.workbench.texteditor/.classpath b/org.eclipse.ui.workbench.texteditor/.classpath deleted file mode 100644 index 4673a9a260d..00000000000 --- a/org.eclipse.ui.workbench.texteditor/.classpath +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src/"/> - <classpathentry kind="src" path="/org.eclipse.core.resources"/> - <classpathentry kind="src" path="/org.eclipse.jface"/> - <classpathentry kind="src" path="/org.eclipse.core.runtime"/> - <classpathentry kind="src" path="/org.eclipse.jface.text"/> - <classpathentry kind="src" path="/org.eclipse.text"/> - <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/> - <classpathentry kind="src" path="/org.eclipse.ui.workbench"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/org.eclipse.ui.workbench.texteditor/.cvsignore b/org.eclipse.ui.workbench.texteditor/.cvsignore deleted file mode 100644 index c5e82d74585..00000000000 --- a/org.eclipse.ui.workbench.texteditor/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/.project b/org.eclipse.ui.workbench.texteditor/.project deleted file mode 100644 index a0fcf5e5955..00000000000 --- a/org.eclipse.ui.workbench.texteditor/.project +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.ui.workbench.texteditor</name> - <comment></comment> - <projects> - <project>org.eclipse.core.resources</project> - <project>org.eclipse.core.runtime</project> - <project>org.eclipse.jface</project> - <project>org.eclipse.jface.text</project> - <project>org.eclipse.text</project> - <project>org.eclipse.ui.workbench</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.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/org.eclipse.ui.workbench.texteditor/build.properties b/org.eclipse.ui.workbench.texteditor/build.properties deleted file mode 100644 index f047590cb51..00000000000 --- a/org.eclipse.ui.workbench.texteditor/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.texteditor.jar = src/ -bin.includes = *.jar,\ - plugin.xml,\ - plugin.properties diff --git a/org.eclipse.ui.workbench.texteditor/plugin.properties b/org.eclipse.ui.workbench.texteditor/plugin.properties deleted file mode 100644 index 4680fe571b7..00000000000 --- a/org.eclipse.ui.workbench.texteditor/plugin.properties +++ /dev/null @@ -1,2 +0,0 @@ -pluginName= Text Editor Framework -providerName= Eclipse.org diff --git a/org.eclipse.ui.workbench.texteditor/plugin.xml b/org.eclipse.ui.workbench.texteditor/plugin.xml deleted file mode 100644 index 28c814638d3..00000000000 --- a/org.eclipse.ui.workbench.texteditor/plugin.xml +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<plugin - id="org.eclipse.ui.workbench.texteditor" - name="%pluginName" - version="2.1.0" - provider-name="%providerName"> - - <runtime> - <library name="texteditor.jar"> - <export name="*"/> - </library> - </runtime> - - <requires> - <import plugin="org.eclipse.text"/> - <import plugin="org.eclipse.jface"/> - <import plugin="org.eclipse.jface.text"/> - <import plugin="org.eclipse.ui.workbench"/> - <import plugin="org.eclipse.core.resources"/> - </requires> - -</plugin> diff --git a/org.eclipse.ui.workbench.texteditor/scripts/exportplugin.xml b/org.eclipse.ui.workbench.texteditor/scripts/exportplugin.xml deleted file mode 100644 index 755041d0318..00000000000 --- a/org.eclipse.ui.workbench.texteditor/scripts/exportplugin.xml +++ /dev/null @@ -1,29 +0,0 @@ -<project name="Export Workbench Text Editor Fragment" default="export" basedir=".."> - <target name="init"> - <tstamp/> - <property name="destdir" value="../../plugin-export" /> - <property name="plugin" value="org.eclipse.ui.workbench.texteditor" /> - <property name="version" value="_2.1.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}/texteditor.jar" - basedir="bin" - /> - <copy file="plugin.xml" todir="${dest}"/> - <copy file="plugin.properties" todir="${dest}"/> - <zip zipfile="${dest}/texteditorsrc.jar"> - <fileset dir="src" /> - </zip> - </target> - -</project>
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractDocumentProvider.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractDocumentProvider.java deleted file mode 100644 index a10ce6ef3f7..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractDocumentProvider.java +++ /dev/null @@ -1,791 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -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.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; - -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.util.Assert; - -import org.eclipse.ui.PlatformUI; - -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - - - -/** - * An abstract implementation of a shareable document provider. - * <p> - * Subclasses must implement <code>createDocument</code>, - * <code>createAnnotationModel</code>, and <code>doSaveDocument</code>. - * </p> - */ -public abstract class AbstractDocumentProvider implements IDocumentProvider, IDocumentProviderExtension { - - - /** - * Collection of all information managed for a connected element. - */ - protected class ElementInfo implements IDocumentListener { - - /** The element for which the info is stored */ - public Object fElement; - /** How often the element has been connected */ - public int fCount; - /** Can the element be saved */ - public boolean fCanBeSaved; - /** The element's document */ - public IDocument fDocument; - /** The element's annotation model */ - public IAnnotationModel fModel; - /** - * Has element state been validated - * @since 2.0 - */ - public boolean fIsStateValidated; - /** - * The status of this element - * @since 2.0 - */ - public IStatus fStatus; - - - /** - * Creates a new element info, initialized with the given - * document and annotation model. - * - * @param document the document - * @param model the annotation model - */ - public ElementInfo(IDocument document, IAnnotationModel model) { - fDocument= document; - fModel= model; - fCount= 0; - fCanBeSaved= false; - fIsStateValidated= false; - } - - /** - * An element info equals another object if this object is an element info - * and if the documents of the two element infos are equal. - * @see Object#equals - */ - public boolean equals(Object o) { - if (o instanceof ElementInfo) { - ElementInfo e= (ElementInfo) o; - return fDocument.equals(e.fDocument); - } - return false; - } - - /* - * @see Object#hashCode - */ - public int hashCode() { - return fDocument.hashCode(); - } - - /* - * @see IDocumentListener#documentChanged(DocumentEvent) - */ - public void documentChanged(DocumentEvent event) { - fCanBeSaved= true; - removeUnchangedElementListeners(fElement, this); - fireElementDirtyStateChanged(fElement, fCanBeSaved); - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - } - }; - - - /** - * Enables a certain behavior. - * Indicates whether this provider should behave as described in - * use case 5 of http://bugs.eclipse.org/bugs/show_bug.cgi?id=10806. - * Current value: <code>false</code> - * @since 2.0 - */ - static final protected boolean PR10806_UC5_ENABLED= false; - - /** - * Enables a certain behavior. - * Indicates whether this provider should behave as described in - * http://bugs.eclipse.org/bugs/show_bug.cgi?id=14469 - * Notes: This contradicts <code>PR10806_UC5_ENABLED</code>. - * Current value: <code>true</code> - * @since 2.0 - */ - static final protected boolean PR14469_ENABLED= true; - - /** - * Constant for representing an ok status. This is considered a value object. - * @since 2.0 - */ - static final protected IStatus STATUS_OK= new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.OK, "OK", null); - - /** - * Constant for representing an error status. This is considered a value object. - * @since 2.0 - */ - static final protected IStatus STATUS_ERROR= new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.INFO, "ERROR", null); - - - /** Information of all connected elements */ - private Map fElementInfoMap= new HashMap(); - /** The element state listeners */ - private List fElementStateListeners= new ArrayList(); - - - /** - * Creates a new document provider. - */ - protected AbstractDocumentProvider() { - } - - /** - * Creates the document for the given element.<p> - * Subclasses must implement this method. - * - * @param element the element - * @return the document - * @exception CoreException if the document could not be created - */ - protected abstract IDocument createDocument(Object element) throws CoreException; - - /** - * Creates an annotation model for the given element. <p> - * Subclasses must implement this method. - * - * @param element the element - * @return the annotation model - * @exception CoreException if the annotation model could not be created - */ - protected abstract IAnnotationModel createAnnotationModel(Object element) throws CoreException; - - /** - * Performs the actual work of saving the given document provided for the - * given element. <p> - * Subclasses must implement this method. - * - * @param monitor a progress monitor to report progress and request cancelation - * @param element the element - * @param document the document - * @param overwrite indicates whether an overwrite should happen if necessary - * @exception CoreException if document could not be stored to the given element - */ - protected abstract void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException; - - - /** - * Returns the element info object for the given element. - * - * @param element the element - * @return the element info object, or <code>null</code> if none - */ - protected ElementInfo getElementInfo(Object element) { - return (ElementInfo) fElementInfoMap.get(element); - } - - /** - * Creates a new element info object for the given element.<p> - * This method is called from <code>connect</code> when an element info needs - * to be created. The <code>AbstractDocumentProvider</code> implementation - * of this method returns a new element info object whose document and - * annotation model are the values of <code>createDocument(element)</code> - * and <code>createAnnotationModel(element)</code>, respectively. Subclasses - * may override. - * - * @param element the element - * @return a new element info object - * @exception CoreException if the document or annotation model could not be created - */ - protected ElementInfo createElementInfo(Object element) throws CoreException { - return new ElementInfo(createDocument(element), createAnnotationModel(element)); - } - - /** - * Disposes of the given element info object. <p> - * This method is called when an element info is disposed. The - * <code>AbstractDocumentProvider</code> implementation of this - * method does nothing. Subclasses may reimplement. - * - * @param element the element - * @param info the element info object - */ - protected void disposeElementInfo(Object element, ElementInfo info) { - } - - /** - * Called on initial creation and when the dirty state of the element - * changes to <code>false</code>. Adds all listeners which must be - * active as long as the element is not dirty. This method is called - * before <code>fireElementDirtyStateChanged</code> or <code> - * fireElementContentReplaced</code> is called. - * Subclasses may extend. - * - * @param element the element - * @param info the element info object - */ - protected void addUnchangedElementListeners(Object element, ElementInfo info) { - if (info.fDocument != null) - info.fDocument.addDocumentListener(info); - } - - /** - * Called when the given element gets dirty. Removes all listeners - * which must be active only when the element is not dirty. This - * method is called before <code>fireElementDirtyStateChanged</code> - * or <code>fireElementContentReplaced</code> is called. - * Subclasses may extend. - * - * @param element the element - * @param info the element info object - */ - protected void removeUnchangedElementListeners(Object element, ElementInfo info) { - if (info.fDocument != null) - info.fDocument.removeDocumentListener(info); - } - - /** - * Enumerates the elements connected via this document provider. - * - * @return the list of elements (element type: <code>Object</code>) - */ - protected Iterator getConnectedElements() { - Set s= new HashSet(); - Set keys= fElementInfoMap.keySet(); - if (keys != null) - s.addAll(keys); - return s.iterator(); - } - - /* - * @see IDocumentProvider#connect - */ - public final void connect(Object element) throws CoreException { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info == null) { - - info= createElementInfo(element); - if (info == null) - info= new ElementInfo(null, null); - - info.fElement= element; - - addUnchangedElementListeners(element, info); - - fElementInfoMap.put(element, info); - if (fElementInfoMap.size() == 1) - connected(); - } - ++ info.fCount; - } - - /** - * This hook method is called when this provider starts managing documents for - * elements. I.e. it is called when the first element gets connected to this provider. - * Subclasses may extend. - * @since 2.0 - */ - protected void connected() { - } - - /* - * @see IDocumentProvider#disconnect - */ - public final void disconnect(Object element) { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - - if (info == null) - return; - - if (info.fCount == 1) { - - fElementInfoMap.remove(element); - removeUnchangedElementListeners(element, info); - disposeElementInfo(element, info); - - if (fElementInfoMap.size() == 0) - disconnected(); - - } else - -- info.fCount; - } - - /** - * This hook method is called when this provider stops managing documents for - * element. I.e. it is called when the last element gets disconnected from this provider. - * Subcalles may extend. - * @since 2.0 - */ - protected void disconnected() { - } - - /* - * @see IDocumentProvider#getDocument - */ - public IDocument getDocument(Object element) { - - if (element == null) - return null; - - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - return (info != null ? info.fDocument : null); - } - - /* - * @see IDocumentProvider#mustSaveDocument - */ - public boolean mustSaveDocument(Object element) { - - if (element == null) - return false; - - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - return (info != null ? info.fCount == 1 && info.fCanBeSaved : false); - } - - /* - * @see IDocumentProvider#getAnnotationModel - */ - public IAnnotationModel getAnnotationModel(Object element) { - - if (element == null) - return null; - - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - return (info != null ? info.fModel : null); - } - - /* - * @see IDocumentProvider#canSaveDocument(Object) - */ - public boolean canSaveDocument(Object element) { - - if (element == null) - return false; - - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - return (info != null ? info.fCanBeSaved : false); - } - - /* - * @see IDocumentProvider#resetDocument(Object) - */ - public void resetDocument(Object element) throws CoreException { - if (element == null) - return; - - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) { - - IDocument original= null; - IStatus status= null; - - try { - original= createDocument(element); - } catch (CoreException x) { - status= x.getStatus(); - } - - info.fStatus= status; - - if (original != null) { - fireElementContentAboutToBeReplaced(element); - info.fDocument.set(original.get()); - if (info.fCanBeSaved) { - info.fCanBeSaved= false; - addUnchangedElementListeners(element, info); - } - fireElementContentReplaced(element); - } - } - } - - /* - * @see IDocumentProvider#saveDocument(IProgressMonitor, Object, IDocument, boolean) - */ - public void saveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { - - if (element == null) - return; - - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) { - - if (info.fDocument != document) { - Status status= new Status(IStatus.WARNING, PlatformUI.PLUGIN_ID, IResourceStatus.ERROR, EditorMessages.getString("AbstractDocumentProvider.error.save.inuse"), null); //$NON-NLS-1$ - throw new CoreException(status); - } - - doSaveDocument(monitor, element, document, overwrite); - info.fCanBeSaved= false; - addUnchangedElementListeners(element, info); - fireElementDirtyStateChanged(element, false); - - } else { - doSaveDocument(monitor, element, document, overwrite); - } - } - - /** - * The <code>AbstractDocumentProvider</code> implementation of this - * <code>IDocumentProvider</code> method does nothing. Subclasses may - * reimplement. - * - * @param element the element - */ - public void aboutToChange(Object element) { - } - - /** - * The <code>AbstractDocumentProvider</code> implementation of this - * <code>IDocumentProvider</code> method does nothing. Subclasses may - * reimplement. - * - * @param element the element - */ - public void changed(Object element) { - } - - /* - * @see IDocumentProvider#addElementStateListener(IElementStateListener) - */ - public void addElementStateListener(IElementStateListener listener) { - Assert.isNotNull(listener); - if (!fElementStateListeners.contains(listener)) - fElementStateListeners.add(listener); - } - - /* - * @see IDocumentProvider#removeElementStateListener(IElementStateListener) - */ - public void removeElementStateListener(IElementStateListener listener) { - Assert.isNotNull(listener); - fElementStateListeners.remove(listener); - } - - /** - * Informs all registered element state listeners about a change in the - * dirty state of the given element. - * - * @param element the element - * @param isDirty the new dirty state - * @see IElementStateListener#elementDirtyStateChanged - */ - protected void fireElementDirtyStateChanged(Object element, boolean isDirty) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - IElementStateListener l= (IElementStateListener) e.next(); - l.elementDirtyStateChanged(element, isDirty); - } - } - - /** - * Informs all registered element state listeners about an impending - * replace of the given element's content. - * - * @param element the element - * @see IElementStateListener#elementContentAboutToBeReplaced - */ - protected void fireElementContentAboutToBeReplaced(Object element) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - IElementStateListener l= (IElementStateListener) e.next(); - l.elementContentAboutToBeReplaced(element); - } - } - - /** - * Informs all registered element state listeners about the just-completed - * replace of the given element's content. - * - * @param element the element - * @see IElementStateListener#elementContentReplaced - */ - protected void fireElementContentReplaced(Object element) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - IElementStateListener l= (IElementStateListener) e.next(); - l.elementContentReplaced(element); - } - } - - /** - * Informs all registered element state listeners about the deletion - * of the given element. - * - * @param element the element - * @see IElementStateListener#elementDeleted - */ - protected void fireElementDeleted(Object element) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - IElementStateListener l= (IElementStateListener) e.next(); - l.elementDeleted(element); - } - } - - /** - * Informs all registered element state listeners about a move. - * - * @param originalElement the element before the move - * @param movedElement the element after the move - * @see IElementStateListener#elementMoved - */ - protected void fireElementMoved(Object originalElement, Object movedElement) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - IElementStateListener l= (IElementStateListener) e.next(); - l.elementMoved(originalElement, movedElement); - } - } - - /* - * @see IDocumentProvider#getModificationStamp(Object) - * @since 2.0 - */ - public long getModificationStamp(Object element) { - return 0; - } - - /* - * @see IDocumentProvider#getSynchronizationStamp(Object) - * @since 2.0 - */ - public long getSynchronizationStamp(Object element) { - return 0; - } - - /* - * @see IDocumentProvider#isDeleted(Object) - * @since 2.0 - */ - public boolean isDeleted(Object element) { - return false; - } - - /* - * @see IDocumentProviderExtension#isReadOnly(Object) - * @since 2.0 - */ - public boolean isReadOnly(Object element) { - return true; - } - - /* - * @see IDocumentProviderExtension#isModifiable(Object) - * @since 2.0 - */ - public boolean isModifiable(Object element) { - return false; - } - - /** - * Returns whether <code>validateState</code> has been called for the given element - * since the element's state has potentially been invalidated. - * - * @param element the element - * @return whether <code>validateState</code> has been called for the given element - * @since 2.0 - */ - public boolean isStateValidated(Object element) { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) - return info.fIsStateValidated; - return false; - } - - /** - * Hook method for validating the state of the given element. Must not take care of cache updating etc. - * Default implementation is empty. - * - * @param element the element - * @param computationContext the context in which validation happens - * @exception CoreException in case validation fails - * @since 2.0 - */ - protected void doValidateState(Object element, Object computationContext) throws CoreException { - } - - /* - * @see IDocumentProviderExtension#validateState(Object, Object) - * @since 2.0 - */ - final public void validateState(Object element, Object computationContext) throws CoreException { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) { - doValidateState(element, computationContext); - doUpdateStateCache(element); - info.fIsStateValidated= true; - fireElementStateValidationChanged(element, true); - } - } - - /** - * Hook method for updating the state of the given element. - * Default implementation is empty. - * - * @param element the element - * @exception CoreException in case state cache updating fails - * @since 2.0 - */ - protected void doUpdateStateCache(Object element) throws CoreException { - } - - /** - * Returns whether the state of the element must be invalidated given its - * previous read-only state. - * - * @param element the element - * @param wasReadOnly the previous read-only state - * @return <code>true</code> if the state of the given element must be invalidated - * @since 2.0 - */ - protected boolean invalidatesState(Object element, boolean wasReadOnly) { - Assert.isTrue(PR10806_UC5_ENABLED != PR14469_ENABLED); - boolean readOnlyChanged= (isReadOnly(element) != wasReadOnly); - if (PR14469_ENABLED) - return readOnlyChanged && !canSaveDocument(element); - return readOnlyChanged; - } - - /* - * @see IDocumentProviderExtension#updateStateCache(Object) - * @since 2.0 - */ - final public void updateStateCache(Object element) throws CoreException { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) { - boolean wasReadOnly= isReadOnly(element); - doUpdateStateCache(element); - if (invalidatesState(element, wasReadOnly)) { - info.fIsStateValidated= false; - fireElementStateValidationChanged(element, false); - } - } - } - - /* - * @see IDocumentProviderExtension#setCanSaveDocument(Object) - * @since 2.0 - */ - public void setCanSaveDocument(Object element) { - if (element != null) { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) { - info.fCanBeSaved= true; - removeUnchangedElementListeners(element, info); - fireElementDirtyStateChanged(element, info.fCanBeSaved); - } - } - } - - /** - * Informs all registered element state listeners about a change in the - * state validation of the given element. - * - * @param element the element - * @param isStateValidated - * @see IElementStateListenerExtension#elementStateValidationChanged(Object, boolean) - * @since 2.0 - */ - protected void fireElementStateValidationChanged(Object element, boolean isStateValidated) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - Object o= e.next(); - if (o instanceof IElementStateListenerExtension) { - IElementStateListenerExtension l= (IElementStateListenerExtension) o; - l.elementStateValidationChanged(element, isStateValidated); - } - } - } - - /** - * Informs all registered element state listeners about the current - * change of the element - * - * @param element the element - * @see IElementStateListenerExtension#elementStateChanging(Object) - * @since 2.0 - */ - protected void fireElementStateChanging(Object element) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - Object o= e.next(); - if (o instanceof IElementStateListenerExtension) { - IElementStateListenerExtension l= (IElementStateListenerExtension) o; - l.elementStateChanging(element); - } - } - } - - /** - * Informs all registered element state listeners about the failed - * change of the element - * - * @param element the element - * @see IElementStateListenerExtension#elementStateChangeFailed(Object) - * @since 2.0 - */ - protected void fireElementStateChangeFailed(Object element) { - Iterator e= new ArrayList(fElementStateListeners).iterator(); - while (e.hasNext()) { - Object o= e.next(); - if (o instanceof IElementStateListenerExtension) { - IElementStateListenerExtension l= (IElementStateListenerExtension) o; - l.elementStateChangeFailed(element); - } - } - } - - /* - * @see IDocumentProviderExtension#getStatus(Object) - * @since 2.0 - */ - public IStatus getStatus(Object element) { - ElementInfo info= (ElementInfo) fElementInfoMap.get(element); - if (info != null) { - if (info.fStatus != null) - return info.fStatus; - return (info.fDocument == null ? STATUS_ERROR : STATUS_OK); - } - - return STATUS_ERROR; - } - - /* - * @see org.eclipse.ui.texteditor.IDocumentProviderExtension#synchronize(Object) - * @since 2.0 - */ - public void synchronize(Object element) throws CoreException { - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractMarkerAnnotationModel.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractMarkerAnnotationModel.java deleted file mode 100644 index d84e2bf2167..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractMarkerAnnotationModel.java +++ /dev/null @@ -1,571 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationModel; -import org.eclipse.jface.util.Assert; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; - -import org.eclipse.ui.PlatformUI; - - -/** - * Abstract implementation of a marker-based annotation model. - * <p> - * Markers are provided by an underlying source (a subclass responsibility). - * Markers whose textual range gets deleted during text editing are removed - * from the model on save. The <code>updateMarkers</code> method can be used - * to force the model to update the source's markers with any changes to their - * locations due to edits. Clients can register <code>IMarkerUpdater</code> - * objects in order to define the process of marker updating. Registration can be done - * using the <code>"org.eclipse.ui.markerUpdaters"</code> extension point. - * <p> - * Subclasses must implement the following methods: - * <ul> - * <li><code>retrieveMarkers</code></li> - * <li><code>isAcceptable</code></li> - * <li><code>deleteMarkers</code></li> - * <li><code>listenToMarkerChanges</code></li> - * </ul> - * </p> - */ -public abstract class AbstractMarkerAnnotationModel extends AnnotationModel { - - /** List of annotations whose text range became invalid because of document changes */ - private List fDeletedAnnotations= new ArrayList(2); - /** Reference counters to track how often an annotation model is connected to its document */ - private HashMap fRefcountTable= new HashMap(); - /** List of registered and instantiated marker updaters */ - private List fInstantiatedMarkerUpdaters= null; - /** List of registered but not yet instantiated marker updaters */ - private List fMarkerUpdaterSpecifications= null; - - - /** - * Retrieves all markers from this model.<p> - * Subclasses must implement this method. - * - * @return the list of markers - * @exception CoreException if there is a problem getting the markers - */ - protected abstract IMarker[] retrieveMarkers() throws CoreException; - - /** - * Deletes the given markers from this model.<p> - * Subclasses must implement this method. - * - * @param markers the list of markers - * @exception CoreException if there are problems deleting the markers - */ - protected abstract void deleteMarkers(IMarker[] markers) throws CoreException; - - /** - * Tells the model whether it should listen for marker changes. <p> - * Subclasses must implement this method. - * - * @param listen <code>true</code> if this model should listen, and - * <code>false</code> otherwise - */ - protected abstract void listenToMarkerChanges(boolean listen); - - /** - * Determines whether the marker is acceptable as an addition to this model. - * If the marker, say, represents an aspect or range of no interest to this - * model, the marker is rejected.<p> - * Subclasses must implement this method. - * - * @param marker the marker - * @return <code>true</code> if the marker is acceptable - */ - protected abstract boolean isAcceptable(IMarker marker); - - /** - * Creates a new annotation model. The annotation model does not manage any - * annotations and is not connected to any document. - */ - protected AbstractMarkerAnnotationModel() { - } - - /** - * Adds the given marker updater to this annotation model. - * It is client's responsibility to ensure the consitency of the - * set of registered marker updaters. - * - * @param markerUpdater the marker updater to be added - */ - protected void addMarkerUpdater(IMarkerUpdater markerUpdater) { - if (!fInstantiatedMarkerUpdaters.contains(markerUpdater)) - fInstantiatedMarkerUpdaters.add(markerUpdater); - } - - /** - * Removes the given marker updater from this annotation model. - * - * @param markerUpdater the marker updater to be removed - */ - protected void removeMarkerUpdater(IMarkerUpdater markerUpdater) { - fInstantiatedMarkerUpdaters.remove(markerUpdater); - } - - /** - * Creates a new annotation for the given marker.<p> - * Subclasses may override. - * - * @param marker the marker - * @return the new marker annotation - */ - protected MarkerAnnotation createMarkerAnnotation(IMarker marker) { - return new MarkerAnnotation(marker); - } - - /** - * Handles an unanticipated <code>CoreException</code> in - * a standard manner. - * - * @param exception the exception - * @param message a message to aid debugging - */ - protected void handleCoreException(CoreException exception, String message) { - - ILog log= Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog(); - - if (message != null) - log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, message, null)); - - log.log(exception.getStatus()); - } - - /** - * Creates and returns the character position of the given marker based - * on its attributes. <p> - * Subclasses may override. - * - * @param marker the marker - * @return the new position or <code>null</code> if no valid position - */ - protected Position createPositionFromMarker(IMarker marker) { - - int start= MarkerUtilities.getCharStart(marker); - int end= MarkerUtilities.getCharEnd(marker); - - if (start > end) { - end= start + end; - start= end - start; - end= end - start; - } - - if (start == -1 && end == -1) { - // marker line number is 1-based - int line= MarkerUtilities.getLineNumber(marker); - if (line > 0 && fDocument != null) { - try { - start= fDocument.getLineOffset(line - 1); - end= start; - } catch (BadLocationException x) { - } - } - } - - if (start > -1 && end > -1) - return new Position(start, end - start); - - return null; - } - - /** - * Creates an annotation for the given marker and adds it to this model. - * Does nothing if the marker is not acceptable to this model. - * - * @param marker the marker - * @see #isAcceptable - */ - protected final void addMarkerAnnotation(IMarker marker) { - - if (isAcceptable(marker)) { - Position p= createPositionFromMarker(marker); - if (p != null) - addAnnotation(createMarkerAnnotation(marker), p, false); - } - } - - /** - * Connects to the source of markers as marker change listener. - * @see AnnotationModel#connected - */ - protected void connected() { - - listenToMarkerChanges(true); - - try { - catchupWithMarkers(); - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("AbstractMarkerAnnotationModel.connected")); //$NON-NLS-1$ - } - - fireModelChanged(); - } - - /** - * Installs all marker updaters for this marker annotation model. - */ - private void installMarkerUpdaters() { - - // initialize lists - indicates that the initialization happened - fMarkerUpdaterSpecifications= new ArrayList(2); - fInstantiatedMarkerUpdaters= new ArrayList(2); - - // populate list - IExtensionPoint extensionPoint= Platform.getPluginRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, "markerUpdaters"); //$NON-NLS-1$ - if (extensionPoint != null) { - IConfigurationElement[] elements= extensionPoint.getConfigurationElements(); - for (int i= 0; i < elements.length; i++) - fMarkerUpdaterSpecifications.add(elements[i]); - } - } - - /** - * Uninstalls all marker updaters. - */ - private void uninstallMarkerUpdaters() { - if (fInstantiatedMarkerUpdaters != null) { - fInstantiatedMarkerUpdaters.clear(); - fInstantiatedMarkerUpdaters= null; - } - - if (fMarkerUpdaterSpecifications != null) { - fMarkerUpdaterSpecifications.clear(); - fMarkerUpdaterSpecifications= null; - } - } - - /** - * Removes the marker change listener. - * @see AnnotationModel#disconnected - */ - protected void disconnected() { - listenToMarkerChanges(false); - uninstallMarkerUpdaters(); - } - - /** - * Returns the position known to this annotation model for the given marker. - * - * @param marker the marker - * @return the position, or <code>null</code> if none - */ - public Position getMarkerPosition(IMarker marker) { - MarkerAnnotation a= getMarkerAnnotation(marker); - if (a != null) { - return (Position) fAnnotations.get(a); - } - return null; - } - - /** - * Updates the annotation corresponding to the given marker which has changed - * in some way. <p> - * Subclasses may override. - * - * @param marker the marker - */ - protected void modifyMarkerAnnotation(IMarker marker) { - MarkerAnnotation a= getMarkerAnnotation(marker); - if (a != null) { - - // update annotation presentation - a.update(); - - // update annotation position - Position p1= createPositionFromMarker(marker); - if (p1 != null) { - Position p0= (Position) fAnnotations.get(a); - p0.setOffset(p1.getOffset()); - p0.setLength(p1.getLength()); - } - } - } - - /* - * @see AnnotationModel#removeAnnotations - */ - protected void removeAnnotations(List annotations, boolean fireModelChanged, boolean modelInitiated) { - if (annotations != null && annotations.size() > 0) { - - List markerAnnotations= new ArrayList(); - for (Iterator e= annotations.iterator(); e.hasNext();) { - Annotation a= (Annotation) e.next(); - if (a instanceof MarkerAnnotation) - markerAnnotations.add(a); - - // remove annotations from annotation model - removeAnnotation(a, false); - } - - if (markerAnnotations.size() > 0) { - - if (modelInitiated) { - // if model initiated also remove it from the marker manager - - listenToMarkerChanges(false); - try { - - IMarker[] m= new IMarker[markerAnnotations.size()]; - for (int i= 0; i < m.length; i++) { - MarkerAnnotation ma = (MarkerAnnotation) markerAnnotations.get(i); - m[i]= ma.getMarker(); - } - deleteMarkers(m); - - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("AbstractMarkerAnnotationModel.removeAnnotations")); //$NON-NLS-1$ - } - listenToMarkerChanges(true); - - } else { - // remember deleted annotations in order to remove their markers later on - fDeletedAnnotations.addAll(markerAnnotations); - } - } - - if (fireModelChanged) - fireModelChanged(); - } - } - - /** - * Removes the annotation corresponding to the given marker. Does nothing - * if there is no annotation for this marker. - * - * @param marker the marker - */ - protected final void removeMarkerAnnotation(IMarker marker) { - MarkerAnnotation a= getMarkerAnnotation(marker); - if (a != null) { - removeAnnotation(a, false); - } - } - - /** - * Re-populates this model with annotations for all markers retrieved - * from the maker source via <code>retrieveMarkers</code>. - * - * @exception CoreException if there is a problem getting the markers - */ - private void catchupWithMarkers() throws CoreException { - - for (Iterator e=getAnnotationIterator(false); e.hasNext();) { - Annotation a= (Annotation) e.next(); - if (a instanceof MarkerAnnotation) - removeAnnotation(a, false); - } - - IMarker[] markers= retrieveMarkers(); - if (markers != null) { - for (int i= 0; i < markers.length; i++) - addMarkerAnnotation(markers[i]); - } - } - - /** - * Returns this model's annotation for the given marker. - * - * @param marker the marker - * @return the annotation, or <code>null</code> if none - */ - public final MarkerAnnotation getMarkerAnnotation(IMarker marker) { - Iterator e= getAnnotationIterator(false); - while (e.hasNext()) { - Object o= e.next(); - if (o instanceof MarkerAnnotation) { - MarkerAnnotation a= (MarkerAnnotation) o; - if (marker.equals(a.getMarker())) { - return a; - } - } - } - return null; - } - - /** - * Creates a marker updater as specified in the given configuration element. - * - * @param element the configuration element - * @return the created marker updater or <code>null</code> if none could be created - */ - private IMarkerUpdater createMarkerUpdater(IConfigurationElement element) { - try { - return (IMarkerUpdater) element.createExecutableExtension("class"); //$NON-NLS-1$ - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("AbstractMarkerAnnotationModel.createMarkerUpdater")); //$NON-NLS-1$ - } - - return null; - } - - /** - * Checks whether a marker updater is registered for the type of the - * given marker but not yet instantiated. If so, the method instantiates - * the marker updater and registers it with this model. - * - * @param marker the marker for which to look for an updater - * @since 2.0 - */ - private void checkMarkerUpdaters(IMarker marker) { - List toBeDeleted= new ArrayList(); - for (int i= 0; i < fMarkerUpdaterSpecifications.size(); i++) { - IConfigurationElement spec= (IConfigurationElement) fMarkerUpdaterSpecifications.get(i); - String markerType= spec.getAttribute("markerType"); //$NON-NLS-1$ - if (markerType == null || MarkerUtilities.isMarkerType(marker, markerType)) { - toBeDeleted.add(spec); - IMarkerUpdater updater= createMarkerUpdater(spec); - if (updater != null) - addMarkerUpdater(updater); - } - } - - for (int i= 0; i < toBeDeleted.size(); i++) - fMarkerUpdaterSpecifications.remove(toBeDeleted.get(i)); - } - - /** - * Updates the given marker according to the given position in the given - * document. If the given position is <code>null</code>, the marker is - * assumed to carry the correct positional information. If it is detected - * that the marker is invalid and should thus be deleted, this method - * returns <code>false</code>. - * - * @param marker the marker to be updated - * @param document the document into which the given position points - * @param position the current position of the marker inside the given document - * @exception CoreException if there is a problem updating the marker - * @since 2.0 - */ - public boolean updateMarker(IMarker marker, IDocument document, Position position) throws CoreException { - - if (fMarkerUpdaterSpecifications == null) - installMarkerUpdaters(); - - if (!fMarkerUpdaterSpecifications.isEmpty()) - checkMarkerUpdaters(marker); - - boolean isOK= true; - - for (int i= 0; i < fInstantiatedMarkerUpdaters.size(); i++) { - IMarkerUpdater updater= (IMarkerUpdater) fInstantiatedMarkerUpdaters.get(i); - String markerType= updater.getMarkerType(); - if (markerType == null || MarkerUtilities.isMarkerType(marker, markerType)) { - - if (position == null) { - /* compatibility code */ - position= createPositionFromMarker(marker); - } - - isOK= (isOK && updater.updateMarker(marker, document, position)); - } - } - - return isOK; - } - - /** - * Updates the markers managed by this annotation model by calling - * all registered marker updaters (<code>IMarkerUpdater</code>). - * - * @param document the document to which this model is currently connected - * @exception CoreException if there is a problem updating the markers - */ - public void updateMarkers(IDocument document) throws CoreException { - - Assert.isTrue(fDocument == document); - - if (fAnnotations.size() == 0 && fDeletedAnnotations.size() == 0) - return; - - if (fMarkerUpdaterSpecifications == null) - installMarkerUpdaters(); - - listenToMarkerChanges(false); - - // update all markers with the positions known by the annotation model - for (Iterator e= getAnnotationIterator(false); e.hasNext();) { - Object o= e.next(); - if (o instanceof MarkerAnnotation) { - MarkerAnnotation a= (MarkerAnnotation) o; - IMarker marker= a.getMarker(); - Position position= (Position) fAnnotations.get(a); - if ( !updateMarker(marker, document, position)) { - if ( !fDeletedAnnotations.contains(a)) - fDeletedAnnotations.add(a); - } - } - } - - if (!fDeletedAnnotations.isEmpty()) { - removeAnnotations(fDeletedAnnotations, true, true); - fDeletedAnnotations.clear(); - } - - listenToMarkerChanges(true); - } - - /** - * Resets all the markers to their original state. - */ - public void resetMarkers() { - - // reinitializes the positions from the markers - for (Iterator e= getAnnotationIterator(false); e.hasNext();) { - Object o= e.next(); - if (o instanceof MarkerAnnotation) { - MarkerAnnotation a= (MarkerAnnotation) o; - Position p= createPositionFromMarker(a.getMarker()); - if (p != null) { - removeAnnotation(a, false); - addAnnotation(a, p, false); - } - } - } - - // add the markers of deleted positions back to the annotation model - for (Iterator e= fDeletedAnnotations.iterator(); e.hasNext();) { - Object o= e.next(); - if (o instanceof MarkerAnnotation) { - MarkerAnnotation a= (MarkerAnnotation) o; - Position p= createPositionFromMarker(a.getMarker()); - if (p != null) - addAnnotation(a, p, false); - } - } - fDeletedAnnotations.clear(); - - // fire annotation model changed - fireModelChanged(); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractRulerActionDelegate.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractRulerActionDelegate.java deleted file mode 100644 index 5752dd163f1..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractRulerActionDelegate.java +++ /dev/null @@ -1,145 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.text.source.IVerticalRulerInfo; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.widgets.Control; - -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; - -/** - * This class serves as an adapter for actions contributed to the vertical ruler's - * context menu. This adapter provides the contributed actions access to their editor - * and the editor's vertical ruler. These actions gain only limited access to the vertical - * ruler as defined by <code>IVerticalRulerInfo</code>. The adapter updates the - * adapter (inner) action on menu and mouse action on the vertical ruler.<p> - * Extending classes must implement the factory method - * <code>createAction(ITextEditor editor, IVerticalRulerInfo)</code>. - * @since 2.0 - */ -public abstract class AbstractRulerActionDelegate implements IEditorActionDelegate, MouseListener, IMenuListener { - - /** The editor. */ - private IEditorPart fEditor; - /** The action calling the action delegate. */ - private IAction fCallerAction; - /** The underlying action. */ - private IAction fAction; - - /** - * The factory method creating the underlying action. - * - * @param editor the editor the action to be created will work on - * @param rulerInfo the vertical ruler the action to be created will work on - * @return the created action - */ - protected abstract IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo); - - - /* - * @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart) - */ - public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) { - if (fEditor != null) { - IVerticalRulerInfo rulerInfo= (IVerticalRulerInfo) fEditor.getAdapter(IVerticalRulerInfo.class); - if (rulerInfo != null) { - Control control= rulerInfo.getControl(); - if (control != null && !control.isDisposed()) - control.removeMouseListener(this); - } - - if (fEditor instanceof ITextEditorExtension) - ((ITextEditorExtension) fEditor).removeRulerContextMenuListener(this); - } - - fEditor= targetEditor; - fCallerAction= callerAction; - fAction= null; - - if (fEditor != null && fEditor instanceof ITextEditor) { - if (fEditor instanceof ITextEditorExtension) - ((ITextEditorExtension) fEditor).addRulerContextMenuListener(this); - - IVerticalRulerInfo rulerInfo= (IVerticalRulerInfo) fEditor.getAdapter(IVerticalRulerInfo.class); - if (rulerInfo != null) { - fAction= createAction((ITextEditor) fEditor, rulerInfo); - update(); - - Control control= rulerInfo.getControl(); - if (control != null && !control.isDisposed()) - control.addMouseListener(this); - } - } - } - - /* - * @see IActionDelegate#run(IAction) - */ - public void run(IAction callerAction) { - if (fAction != null) - fAction.run(); - } - - /* - * @see IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - } - - /** - * Requests the adaptee to update itself to the current state. - */ - private void update() { - if (fAction != null && fAction instanceof IUpdate) { - ((IUpdate) fAction).update(); - if (fCallerAction != null) { - fCallerAction.setText(fAction.getText()); - fCallerAction.setEnabled(fAction.isEnabled()); - } - } - } - - /* - * @see IMenuListener#menuAboutToShow(IMenuManager) - */ - public void menuAboutToShow(IMenuManager manager) { - update(); - } - - /* - * @see MouseListener#mouseDoubleClick(MouseEvent) - */ - public void mouseDoubleClick(MouseEvent e) { - } - - /* - * @see MouseListener#mouseDown(MouseEvent) - */ - public void mouseDown(MouseEvent e) { - update(); - } - - /* - * @see MouseListener#mouseUp(MouseEvent) - */ - public void mouseUp(MouseEvent e) { - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java deleted file mode 100644 index 573de31c337..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java +++ /dev/null @@ -1,3588 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import java.lang.reflect.InvocationTargetException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -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.custom.ST; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.custom.VerifyKeyListener; -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.ShellAdapter; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.IPluginPrerequisite; -import org.eclipse.core.runtime.IPluginRegistry; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IFindReplaceTarget; -import org.eclipse.jface.text.IFindReplaceTargetExtension; -import org.eclipse.jface.text.IMarkRegionTarget; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.IRewriteTarget; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.ITextViewerExtension; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.IVerticalRuler; -import org.eclipse.jface.text.source.IVerticalRulerExtension; -import org.eclipse.jface.text.source.IVerticalRulerInfo; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.jface.text.source.VerticalRuler; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -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.ui.*; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorActionBarContributor; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IKeyBindingService; -import org.eclipse.ui.INavigationLocationProvider; -import org.eclipse.ui.IPartListener; -import org.eclipse.ui.IReusableEditor; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.internal.EditorPluginAction; -import org.eclipse.ui.part.EditorActionBarContributor; -import org.eclipse.ui.part.EditorPart; - - - - -/** - * Abstract base implementation of a text editor. - * <p> - * Subclasses are responsible for configuring the editor appropriately. - * The standard text editor, <code>TextEditor</code>, is one such example. - * </p> - * <p> - * If a subclass calls <code>setEditorContextMenuId</code> the arguments is - * used as the id under which the editor's context menu is registered for extensions. - * If no id is set, the context menu is registered under <b>[editor_id].EditorContext</b> - * whereby [editor_id] is replaced with the editor's part id. If the editor is instructed to - * run in version 1.0 context menu registration compatibility mode, the latter form of the - * registration even happens if a context menu id has been set via <code>setEditorContextMenuId</code>. - * If no id is set while in compatibility mode, the menu is registered under - * <code>DEFAULT_EDITOR_CONTEXT_MENU_ID</code>. - * </p> - * <p> - * If a subclass calls <code>setRulerContextMenuId</code> the arguments is - * used as the id under which the ruler's context menu is registered for extensions. - * If no id is set, the context menu is registered under <b>[editor_id].RulerContext</b> - * whereby [editor_id] is replaced with the editor's part id. If the editor is instructed to - * run in version 1.0 context menu registration compatibility mode, the latter form of the - * registration even happens if a context menu id has been set via <code>setRulerContextMenuId</code>. - * If no id is set while in compatibility mode, the menu is registered under - * <code>DEFAULT_RULER_CONTEXT_MENU_ID</code>. - * </p> - * - * @see org.eclipse.ui.editors.text.TextEditor - */ -public abstract class AbstractTextEditor extends EditorPart implements ITextEditor, IReusableEditor, ITextEditorExtension, INavigationLocationProvider { - - /** - * Tag used in xml configuration files to specify editor action contributions. - * Current value: <code>editorContribution</code> - * @since 2.0 - */ - private static final String TAG_CONTRIBUTION_TYPE= "editorContribution"; //$NON-NLS-1$ - - /** - * Internal element state listener. - */ - class ElementStateListener implements IElementStateListener, IElementStateListenerExtension { - - /** - * Internal <code>VerifyListener</code> for performing the state validation of the - * editor input in case of the first attempted manipulation via typing on the keyboard. - * @since 2.0 - */ - class Validator implements VerifyListener { - - /** Indicates whether the editor input changed during the process of state validation. */ - private boolean fInputChanged; - /** Detector for editor input changes during the process of state validation. */ - private ITextInputListener fInputListener= new ITextInputListener() { - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {} - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { fInputChanged= true; } - }; - - /* - * @see VerifyListener#verifyText(VerifyEvent) - */ - public void verifyText(VerifyEvent e) { - - ISourceViewer viewer= getSourceViewer(); - fInputChanged= false; - viewer.addTextInputListener(fInputListener); - try { - validateState(getEditorInput()); - sanityCheckState(getEditorInput()); - if (isEditorInputReadOnly() || fInputChanged) - e.doit= false; - } finally { - viewer.removeTextInputListener(fInputListener); - } - } - }; - - /** - * The listener's validator. - * @since 2.0 - */ - private Validator fValidator; - - /* - * @see IElementStateListenerExtension#elementStateValidationChanged(Object, boolean) - * @since 2.0 - */ - public void elementStateValidationChanged(Object element, boolean isStateValidated) { - - if (element != null && element.equals(getEditorInput())) { - - enableSanityChecking(true); - - if (isStateValidated && fValidator != null) { - ISourceViewer viewer= getSourceViewer(); - if (viewer != null) { - StyledText textWidget= viewer.getTextWidget(); - if (textWidget != null && !textWidget.isDisposed()) - textWidget.removeVerifyListener(fValidator); - fValidator= null; - } - } else if (!isStateValidated && fValidator == null) { - ISourceViewer viewer= getSourceViewer(); - if (viewer != null) { - StyledText textWidget= viewer.getTextWidget(); - if (textWidget != null && !textWidget.isDisposed()) { - fValidator= new Validator(); - textWidget.addVerifyListener(fValidator); - } - } - } - - } - } - - /* - * @see IElementStateListener#elementDirtyStateChanged - */ - public void elementDirtyStateChanged(Object element, boolean isDirty) { - if (element != null && element.equals(getEditorInput())) { - enableSanityChecking(true); - firePropertyChange(PROP_DIRTY); - } - } - - /* - * @see IElementStateListener#elementContentAboutToBeReplaced - */ - public void elementContentAboutToBeReplaced(Object element) { - if (element != null && element.equals(getEditorInput())) { - enableSanityChecking(true); - rememberSelection(); - resetHighlightRange(); - } - } - - /* - * @see IElementStateListener#elementContentReplaced - */ - public void elementContentReplaced(Object element) { - if (element != null && element.equals(getEditorInput())) { - enableSanityChecking(true); - firePropertyChange(PROP_DIRTY); - restoreSelection(); - } - } - - /* - * @see IElementStateListener#elementDeleted - */ - public void elementDeleted(Object deletedElement) { - if (deletedElement != null && deletedElement.equals(getEditorInput())) { - enableSanityChecking(true); - close(false); - } - } - - /* - * @see IElementStateListener#elementMoved - */ - public void elementMoved(Object originalElement, Object movedElement) { - - if (originalElement != null && originalElement.equals(getEditorInput())) { - - enableSanityChecking(true); - - if (!canHandleMove((IEditorInput) originalElement, (IEditorInput) movedElement)) { - close(true); - return; - } - - if (movedElement == null || movedElement instanceof IEditorInput) { - rememberSelection(); - - IDocumentProvider d= getDocumentProvider(); - IDocument changed= null; - if (isDirty()) - changed= d.getDocument(getEditorInput()); - - setInput((IEditorInput) movedElement); - - if (changed != null) { - d.getDocument(getEditorInput()).set(changed.get()); - validateState(getEditorInput()); - updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE); - } - - restoreSelection(); - } - } - } - - /* - * @see IElementStateListenerExtension#elementStateChanging(Object) - * @since 2.0 - */ - public void elementStateChanging(Object element) { - if (element != null && element.equals(getEditorInput())) - enableSanityChecking(false); - } - - /* - * @see IElementStateListenerExtension#elementStateChangeFailed(Object) - * @since 2.0 - */ - public void elementStateChangeFailed(Object element) { - if (element != null && element.equals(getEditorInput())) - enableSanityChecking(true); - } - }; - - /** - * Internal text listener for updating all content dependent - * actions. The updating is done asynchronously. - */ - class TextListener implements ITextListener { - - /** The posted updater code. */ - private Runnable fRunnable= new Runnable() { - public void run() { - if (fSourceViewer != null) { - // check whether editor has not been disposed yet - updateContentDependentActions(); - } - } - }; - - /** Display used for posting the updater code. */ - private Display fDisplay; - - /* - * @see ITextListener#textChanged(TextEvent) - */ - public void textChanged(TextEvent event) { - - /* - * Also works for text events which do not base on a DocumentEvent. - * This way, if the visible document of the viewer changes, all content - * dependent actions are updated as well. - */ - - if (fDisplay == null) - fDisplay= getSite().getShell().getDisplay(); - - fDisplay.asyncExec(fRunnable); - } - }; - - /** - * Compare configuration elements according to the prerequisite relation - * of their defining plug-ins. - * @since 2.0 - */ - static class ConfigurationElementComparator implements Comparator { - - /* - * @see Comparator#compare(Object, Object) - * @since 2.0 - */ - public int compare(Object object0, Object object1) { - - IConfigurationElement element0= (IConfigurationElement)object0; - IConfigurationElement element1= (IConfigurationElement)object1; - - if (dependsOn(element0, element1)) - return -1; - - if (dependsOn(element1, element0)) - return +1; - - return 0; - } - - /** - * Returns whether one configuration element depends on the other element. Does this by - * checking the dependency chain of the defining plugins. - * - * @param element0 the first element - * @param element1 the second element - * @return <code>true</code> if <code>element0</code> depends on <code>element1</code>. - * @since 2.0 - */ - private static boolean dependsOn(IConfigurationElement element0, IConfigurationElement element1) { - IPluginDescriptor descriptor0= element0.getDeclaringExtension().getDeclaringPluginDescriptor(); - IPluginDescriptor descriptor1= element1.getDeclaringExtension().getDeclaringPluginDescriptor(); - - return dependsOn(descriptor0, descriptor1); - } - - /** - * Returns whether one plugin depends on the other plugin. - * - * @param descriptor0 descriptor of the first plugin - * @param descriptor1 descriptor of the second plugin - * @return <code>true</code> if <code>descriptor0</code> depends on <code>descriptor1</code>. - * @since 2.0 - */ - private static boolean dependsOn(IPluginDescriptor descriptor0, IPluginDescriptor descriptor1) { - - IPluginRegistry registry= Platform.getPluginRegistry(); - IPluginPrerequisite[] prerequisites= descriptor0.getPluginPrerequisites(); - - for (int i= 0; i < prerequisites.length; i++) { - IPluginPrerequisite prerequisite= prerequisites[i]; - String id= prerequisite.getUniqueIdentifier(); - IPluginDescriptor descriptor= registry.getPluginDescriptor(id); - - if (descriptor != null && (descriptor.equals(descriptor1) || dependsOn(descriptor, descriptor1))) - return true; - } - - return false; - } - } - - /** - * Internal property change listener for handling changes in the editor's preferences. - */ - class PropertyChangeListener implements IPropertyChangeListener { - /* - * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent event) { - handlePreferenceStoreChanged(event); - } - }; - - /** - * Internal key verify listener for triggering action activation codes. - */ - class ActivationCodeTrigger implements VerifyKeyListener { - - /** Indicates whether this trigger has been installed. */ - private boolean fIsInstalled= false; - /** - * The key binding service to use. - * @since 2.0 - */ - private IKeyBindingService fKeyBindingService; - - /* - * @see VerifyKeyListener#verifyKey(VerifyEvent) - */ - public void verifyKey(VerifyEvent event) { - - ActionActivationCode code= null; - int size= fActivationCodes.size(); - for (int i= 0; i < size; i++) { - code= (ActionActivationCode) fActivationCodes.get(i); - if (code.matches(event)) { - IAction action= getAction(code.fActionId); - if (action != null) { - - if (action instanceof IUpdate) - ((IUpdate) action).update(); - - if (!action.isEnabled() && action instanceof IReadOnlyDependent) { - IReadOnlyDependent dependent= (IReadOnlyDependent) action; - boolean writable= dependent.isEnabled(true); - if (writable) { - event.doit= false; - return; - } - } else if (action.isEnabled()) { - event.doit= false; - action.run(); - return; - } - } - } - } - if (fKeyBindingService.processKey(event)) - event.doit= false; - } - - /** - * Installs this trigger on the editor's text widget. - * @since 2.0 - */ - public void install() { - if (!fIsInstalled) { - - if (fSourceViewer instanceof ITextViewerExtension) { - ITextViewerExtension e= (ITextViewerExtension) fSourceViewer; - e.prependVerifyKeyListener(this); - } else { - StyledText text= fSourceViewer.getTextWidget(); - text.addVerifyKeyListener(this); - } - - fKeyBindingService= getEditorSite().getKeyBindingService(); - fKeyBindingService.enable(true); - fIsInstalled= true; - } - } - - /** - * Uninstalls this trigger from the editor's text widget. - * @since 2.0 - */ - public void uninstall() { - if (fIsInstalled) { - - if (fSourceViewer instanceof ITextViewerExtension) { - ITextViewerExtension e= (ITextViewerExtension) fSourceViewer; - e.removeVerifyKeyListener(this); - } else if (fSourceViewer != null) { - StyledText text= fSourceViewer.getTextWidget(); - if (text != null && !text.isDisposed()) - text.removeVerifyKeyListener(fActivationCodeTrigger); - } - - fIsInstalled= false; - fKeyBindingService= null; - } - } - - /** - * Registers the given action for key activation. - * @param action the action to be registered - * @since 2.0 - */ - public void registerActionForKeyActivation(IAction action) { - if (action.getActionDefinitionId() != null) - fKeyBindingService.registerAction(action); - } - - /** - * The given action is no longer available for key activation - * @param action the action to be unregistered - * @since 2.0 - */ - public void unregisterActionFromKeyActivation(IAction action) { - // No such action available on the service - } - }; - - /** - * Representation of action activation codes. - */ - static class ActionActivationCode { - - public String fActionId; - public char fCharacter; - public int fKeyCode= -1; - public int fStateMask= SWT.DEFAULT; - - /** - * Creates a new action activation code for the given action id. - * @param actionId the action id - */ - public ActionActivationCode(String actionId) { - fActionId= actionId; - } - - /** - * Returns <code>true</code> if this activation code matches the given verify event. - * @param event the event to test for matching - */ - public boolean matches(VerifyEvent event) { - return (event.character == fCharacter && - (fKeyCode == -1 || event.keyCode == fKeyCode) && - (fStateMask == SWT.DEFAULT || event.stateMask == fStateMask)); - } - }; - - /** - * Internal part and shell activation listener for triggering state validation. - * @since 2.0 - */ - class ActivationListener extends ShellAdapter implements IPartListener { - - /** Cache of the active workbench part. */ - private IWorkbenchPart fActivePart; - /** Indicates whether activation handling is currently be done. */ - private boolean fIsHandlingActivation= false; - - /* - * @see IPartListener#partActivated(IWorkbenchPart) - */ - public void partActivated(IWorkbenchPart part) { - fActivePart= part; - handleActivation(); - } - - /* - * @see IPartListener#partBroughtToTop(IWorkbenchPart) - */ - public void partBroughtToTop(IWorkbenchPart part) { - } - - /* - * @see IPartListener#partClosed(IWorkbenchPart) - */ - public void partClosed(IWorkbenchPart part) { - } - - /* - * @see IPartListener#partDeactivated(IWorkbenchPart) - */ - public void partDeactivated(IWorkbenchPart part) { - fActivePart= null; - } - - /* - * @see IPartListener#partOpened(IWorkbenchPart) - */ - public void partOpened(IWorkbenchPart part) { - } - - /* - * @see ShellListener#shellActivated(ShellEvent) - */ - public void shellActivated(ShellEvent e) { - /* - * Workaround for problem described in - * http://dev.eclipse.org/bugs/show_bug.cgi?id=11731 - * Will be removed when SWT has solved the problem. - */ - e.widget.getDisplay().asyncExec(new Runnable() { - public void run() { - handleActivation(); - } - }); - } - - /** - * Handles the activation triggering a element state check in the editor. - */ - private void handleActivation() { - if (fIsHandlingActivation) - return; - - if (fActivePart == AbstractTextEditor.this) { - fIsHandlingActivation= true; - try { - safelySanityCheckState(getEditorInput()); - } finally { - fIsHandlingActivation= false; - } - } - } - }; - - /** - * Internal interface for a cursor listener. I.e. aggregation - * of mouse and key listener. - * @since 2.0 - */ - interface ICursorListener extends MouseListener, KeyListener { - }; - - /** - * Maps an action definition id to an StyledText action. - * @since 2.0 - */ - static class IdMapEntry { - - /** The action id */ - private String fActionId; - /** The StyledText action */ - private int fAction; - - /** - * Creates a new mapping. - * @param actionId the action id - * @param action the StyledText action - */ - public IdMapEntry(String actionId, int action) { - fActionId= actionId; - fAction= action; - } - - /** - * Returns the action id. - * @return the action id - */ - public String getActionId() { - return fActionId; - } - - /** - * Returns the action - * @return the action - */ - public int getAction() { - return fAction; - } - }; - - /** - * Internal action to scroll the editor's viewer by a specified number of lines. - * @since 2.0 - */ - class ScrollLinesAction extends Action { - - /** Number of lines to scroll. */ - private int fScrollIncrement; - - /** - * Creates a new scroll action that scroll the given number of lines. If the - * increment is < 0, it's scrolling up, if > 0 it's scrolling down. - * @param scrollIncrement the number of lines to scroll - */ - public ScrollLinesAction(int scrollIncrement) { - fScrollIncrement= scrollIncrement; - } - - /* - * @see IAction#run() - */ - public void run() { - ISourceViewer viewer= getSourceViewer(); - int topIndex= viewer.getTopIndex(); - int newTopIndex= Math.max(0, topIndex + fScrollIncrement); - viewer.setTopIndex(newTopIndex); - } - }; - - /** - * @since 2.1 - */ - class ToggleInsertModeAction extends TextNavigationAction { - - public ToggleInsertModeAction(StyledText textWidget) { - super(textWidget, ST.TOGGLE_OVERWRITE); - } - - /* - * @see org.eclipse.jface.action.IAction#run() - */ - public void run() { - super.run(); - fOverwriting= !fOverwriting; - handleInsertModeChanged(); - } - - }; - - /** - * Internal action to show the editor's ruler context menu (accessibility). - * @since 2.0 - */ - class ShowRulerContextMenuAction extends Action { - - /* - * @see IAction#run() - */ - public void run() { - if (fSourceViewer == null) - return; - - StyledText text= fSourceViewer.getTextWidget(); - if (text == null || text.isDisposed()) - return; - - Point location= text.getLocationAtOffset(text.getCaretOffset()); - location.x= 0; - - if (fVerticalRuler instanceof IVerticalRulerExtension) - ((IVerticalRulerExtension) fVerticalRuler).setLocationOfLastMouseButtonActivity(location.x, location.y); - - location= text.toDisplay(location); - fRulerContextMenu.setLocation(location.x, location.y); - fRulerContextMenu.setVisible(true); - } - }; - - - /** - * Editor specific selection provider which wraps the source viewer's selection provider. - * - */ - class SelectionProvider implements ISelectionProvider { - - /* - * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(ISelectionChangedListener) - */ - public void addSelectionChangedListener(ISelectionChangedListener listener) { - if (fSourceViewer != null) - fSourceViewer.getSelectionProvider().addSelectionChangedListener(listener); - } - - /* - * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() - */ - public ISelection getSelection() { - return doGetSelection(); - } - - /* - * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(ISelectionChangedListener) - */ - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - if (fSourceViewer != null) - fSourceViewer.getSelectionProvider().removeSelectionChangedListener(listener); - } - - /* - * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(ISelection) - */ - public void setSelection(ISelection selection) { - doSetSelection(selection); - } - }; - - - - /** Key used to look up font preference */ - public final static String PREFERENCE_FONT= JFaceResources.TEXT_FONT; - /** - * Key used to look up foreground color preference - * Value: <code>AbstractTextEditor.Color.Foreground</code> - * @since 2.0 - */ - public final static String PREFERENCE_COLOR_FOREGROUND= "AbstractTextEditor.Color.Foreground"; //$NON-NLS-1$ - /** - * Key used to look up background color preference - * Value: <code>AbstractTextEditor.Color.Background</code> - * @since 2.0 - */ - public final static String PREFERENCE_COLOR_BACKGROUND= "AbstractTextEditor.Color.Background"; //$NON-NLS-1$ - /** - * Key used to look up foreground color system default preference - * Value: <code>AbstractTextEditor.Color.Foreground.SystemDefault</code> - * @since 2.0 - */ - public final static String PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT= "AbstractTextEditor.Color.Foreground.SystemDefault"; //$NON-NLS-1$ - /** - * Key used to look up background color system default preference - * Value: <code>AbstractTextEditor.Color.Background.SystemDefault</code> - * @since 2.0 - */ - public final static String PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT= "AbstractTextEditor.Color.Background.SystemDefault"; //$NON-NLS-1$ - /** - * Key used to look up find scope background color preference - * Value: <code>AbstractTextEditor.Color.FindScope</code> - * @since 2.0 - */ - public final static String PREFERENCE_COLOR_FIND_SCOPE= "AbstractTextEditor.Color.FindScope"; //$NON-NLS-1$ - - /** Menu id for the editor context menu. */ - public final static String DEFAULT_EDITOR_CONTEXT_MENU_ID= "#EditorContext"; //$NON-NLS-1$ - /** Menu id for the ruler context menu. */ - public final static String DEFAULT_RULER_CONTEXT_MENU_ID= "#RulerContext"; //$NON-NLS-1$ - - /** The width of the vertical ruler */ - protected final static int VERTICAL_RULER_WIDTH= 12; - - /** - * The complete mapping between action definition ids used by eclipse and StyledText actions. - * @since 2.0 - */ - protected final static IdMapEntry[] ACTION_MAP= new IdMapEntry[] { - // navigation - new IdMapEntry(ITextEditorActionDefinitionIds.LINE_UP, ST.LINE_UP), - new IdMapEntry(ITextEditorActionDefinitionIds.LINE_DOWN, ST.LINE_DOWN), - new IdMapEntry(ITextEditorActionDefinitionIds.LINE_START, ST.LINE_START), - new IdMapEntry(ITextEditorActionDefinitionIds.LINE_END, ST.LINE_END), - new IdMapEntry(ITextEditorActionDefinitionIds.COLUMN_PREVIOUS, ST.COLUMN_PREVIOUS), - new IdMapEntry(ITextEditorActionDefinitionIds.COLUMN_NEXT, ST.COLUMN_NEXT), - new IdMapEntry(ITextEditorActionDefinitionIds.PAGE_UP, ST.PAGE_UP), - new IdMapEntry(ITextEditorActionDefinitionIds.PAGE_DOWN, ST.PAGE_DOWN), - new IdMapEntry(ITextEditorActionDefinitionIds.WORD_PREVIOUS, ST.WORD_PREVIOUS), - new IdMapEntry(ITextEditorActionDefinitionIds.WORD_NEXT, ST.WORD_NEXT), - new IdMapEntry(ITextEditorActionDefinitionIds.TEXT_START, ST.TEXT_START), - new IdMapEntry(ITextEditorActionDefinitionIds.TEXT_END, ST.TEXT_END), - new IdMapEntry(ITextEditorActionDefinitionIds.WINDOW_START, ST.WINDOW_START), - new IdMapEntry(ITextEditorActionDefinitionIds.WINDOW_END, ST.WINDOW_END), - // selection - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_LINE_UP, ST.SELECT_LINE_UP), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_LINE_DOWN, ST.SELECT_LINE_DOWN), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_LINE_START, ST.SELECT_LINE_START), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_LINE_END, ST.SELECT_LINE_END), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_COLUMN_PREVIOUS, ST.SELECT_COLUMN_PREVIOUS), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_COLUMN_NEXT, ST.SELECT_COLUMN_NEXT), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_PAGE_UP, ST.SELECT_PAGE_UP), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_PAGE_DOWN, ST.SELECT_PAGE_DOWN), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_WORD_PREVIOUS, ST.SELECT_WORD_PREVIOUS), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_WORD_NEXT, ST.SELECT_WORD_NEXT), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_TEXT_START, ST.SELECT_TEXT_START), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_TEXT_END, ST.SELECT_TEXT_END), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_WINDOW_START, ST.SELECT_WINDOW_START), - new IdMapEntry(ITextEditorActionDefinitionIds.SELECT_WINDOW_END, ST.SELECT_WINDOW_END), - // modification - new IdMapEntry(ITextEditorActionDefinitionIds.CUT, ST.CUT), - new IdMapEntry(ITextEditorActionDefinitionIds.COPY, ST.COPY), - new IdMapEntry(ITextEditorActionDefinitionIds.PASTE, ST.PASTE), - new IdMapEntry(ITextEditorActionDefinitionIds.DELETE_PREVIOUS, ST.DELETE_PREVIOUS), - new IdMapEntry(ITextEditorActionDefinitionIds.DELETE_NEXT, ST.DELETE_NEXT) - }; - - - private final String fReadOnlyLabel = EditorMessages.getString("Editor.statusline.state.readonly.label"); //$NON-NLS-1$ - private final String fWritableLabel = EditorMessages.getString("Editor.statusline.state.writable.label"); //$NON-NLS-1$ - private final String fInsertModeLabel = EditorMessages.getString("Editor.statusline.mode.insert.label"); //$NON-NLS-1$ - private final String fOverwriteModeLabel = EditorMessages.getString("Editor.statusline.mode.overwrite.label"); //$NON-NLS-1$ - - private static class PositionLabelValue { - - public int fValue; - - public String toString() { - return String.valueOf(fValue); - } - }; - - /** The error message shown in the status line in case of failed information look up. */ - protected final String fErrorLabel= EditorMessages.getString("Editor.statusline.error.label"); //$NON-NLS-1$ - private final String fPositionLabelPattern= EditorMessages.getString("Editor.statusline.position.pattern"); //$NON-NLS-1$ - private final PositionLabelValue fLineLabel= new PositionLabelValue(); - private final PositionLabelValue fColumnLabel= new PositionLabelValue(); - private final Object[] fPositionLabelPatternArguments= new Object[] { fLineLabel, fColumnLabel }; - - - - - /** The editor's internal document provider */ - private IDocumentProvider fInternalDocumentProvider; - /** The editor's external document provider */ - private IDocumentProvider fExternalDocumentProvider; - /** The editor's preference store */ - private IPreferenceStore fPreferenceStore; - /** The editor's range indicator */ - private Annotation fRangeIndicator; - /** The editor's source viewer configuration */ - private SourceViewerConfiguration fConfiguration; - /** The editor's source viewer */ - private ISourceViewer fSourceViewer; - /** The editor's selection provider */ - private SelectionProvider fSelectionProvider= new SelectionProvider(); - /** The editor's font */ - private Font fFont; - /** - * The editor's foreground color - * @since 2.0 - */ - private Color fForegroundColor; - /** - * The editor's background color - * @since 2.0 - */ - private Color fBackgroundColor; - /** - * The find scope's highlight color - * @since 2.0 - */ - private Color fFindScopeHighlightColor; - - /** The editor's status line */ - private IEditorStatusLine fEditorStatusLine; - /** The editor's vertical ruler */ - private IVerticalRuler fVerticalRuler; - /** The editor's context menu id */ - private String fEditorContextMenuId; - /** The ruler's context menu id */ - private String fRulerContextMenuId; - /** The editor's help context id */ - private String fHelpContextId; - /** The editor's presentation mode */ - private boolean fShowHighlightRangeOnly; - /** The actions registered with the editor */ - private Map fActions= new HashMap(10); - /** The actions marked as selection dependent */ - private List fSelectionActions= new ArrayList(5); - /** The actions marked as content dependent */ - private List fContentActions= new ArrayList(5); - /** - * The actions marked as property dependent - * @since 2.0 - */ - private List fPropertyActions= new ArrayList(5); - /** - * The actions marked as state dependent - * @since 2.0 - */ - private List fStateActions= new ArrayList(5); - /** The editor's action activation codes */ - private List fActivationCodes= new ArrayList(2); - /** The verify key listener for activation code triggering */ - private ActivationCodeTrigger fActivationCodeTrigger= new ActivationCodeTrigger(); - /** Context menu listener */ - private IMenuListener fMenuListener; - /** Vertical ruler mouse listener */ - private MouseListener fMouseListener; - /** Selection changed listener */ - private ISelectionChangedListener fSelectionChangedListener; - /** Title image to be disposed */ - private Image fTitleImage; - /** The text context menu to be disposed */ - private Menu fTextContextMenu; - /** The ruler context menu to be disposed */ - private Menu fRulerContextMenu; - /** The editor's element state listener */ - private IElementStateListener fElementStateListener= new ElementStateListener(); - /** The editor's text listener */ - private ITextListener fTextListener= new TextListener(); - /** The editor's property change listener */ - private IPropertyChangeListener fPropertyChangeListener= new PropertyChangeListener(); - /** The current navigation history location */ - private INavigationLocation fUserCurrentLocation; - - /** - * The editor's activation listener - * @since 2.0 - */ - private ActivationListener fActivationListener= new ActivationListener(); - /** - * The map of the editor's status fields - * @since 2.0 - */ - private Map fStatusFields; - /** - * The editor's cursor listener - * @since 2.0 - */ - private ICursorListener fCursorListener; - /** - * The editor's insert mode - * @since 2.0 - */ - private boolean fOverwriting= false; - /** - * The editor's remembered text selection - * @since 2.0 - */ - private ISelection fRememberedSelection; - /** - * Indicates whether the editor runs in 1.0 context menu registration compatibility mode - * @since 2.0 - */ - private boolean fCompatibilityMode= true; - /** - * The number of reentrances into error correction code while saving - * @since 2.0 - */ - private int fErrorCorrectionOnSave; - /** - * The delete line target. - */ - private DeleteLineTarget fDeleteLineTarget; - /** - * The incremental find target - * @since 2.0 - */ - private IncrementalFindTarget fIncrementalFindTarget; - /** - * The mark region target - * @since 2.0 - */ - private IMarkRegionTarget fMarkRegionTarget; - /** - * Cached modification stamp of the editor's input - * @since 2.0 - */ - private long fModificationStamp= -1; - /** - * Ruler context menu listeners. - * @since 2.0 - */ - private List fRulerContextMenuListeners= new ArrayList(); - /** - * Indicates whether sanity checking in enabled. - * @since 2.0 - */ - private boolean fIsSanityCheckEnabled= true; - - - - /** - * Creates a new text editor. If not explicitly set, this editor uses - * a <code>SourceViewerConfiguration</code> to configure its - * source viewer. This viewer does not have a range indicator installed, - * nor any menu id set. By default, the created editor runs in 1.0 context - * menu registration compatibility mode. - */ - protected AbstractTextEditor() { - super(); - fEditorContextMenuId= null; - fRulerContextMenuId= null; - fHelpContextId= null; - } - - /* - * @see ITextEditor#getDocumentProvider - */ - public IDocumentProvider getDocumentProvider() { - if (fInternalDocumentProvider != null) - return fInternalDocumentProvider; - return fExternalDocumentProvider; - } - - /** - * Returns the editor's range indicator. - * - * @return the editor's range indicator - */ - protected final Annotation getRangeIndicator() { - return fRangeIndicator; - } - - /** - * Returns the editor's source viewer configuration. - * - * @return the editor's source viewer configuration - */ - protected final SourceViewerConfiguration getSourceViewerConfiguration() { - return fConfiguration; - } - - /** - * Returns the editor's source viewer. - * - * @return the editor's source viewer - */ - protected final ISourceViewer getSourceViewer() { - return fSourceViewer; - } - - /** - * Returns the editor's vertical ruler. - * - * @return the editor's vertical ruler - */ - protected final IVerticalRuler getVerticalRuler() { - return fVerticalRuler; - } - - /** - * Returns the editor's context menu id. - * - * @return the editor's context menu id - */ - protected final String getEditorContextMenuId() { - return fEditorContextMenuId; - } - - /** - * Returns the ruler's context menu id. - * - * @return the ruler's context menu id - */ - protected final String getRulerContextMenuId() { - return fRulerContextMenuId; - } - - /** - * Returns the editor's help context id. - * - * @return the editor's help context id - */ - protected final String getHelpContextId() { - return fHelpContextId; - } - - /** - * Returns this editor's preference store. - * - * @return this editor's preference store - */ - protected final IPreferenceStore getPreferenceStore() { - return fPreferenceStore; - } - - /** - * Sets this editor's document provider. This method must be - * called before the editor's control is created. - * - * @param provider the document provider - */ - protected void setDocumentProvider(IDocumentProvider provider) { - Assert.isNotNull(provider); - fInternalDocumentProvider= provider; - } - - /** - * Sets this editor's source viewer configuration used to configure its - * internal source viewer. This method must be called before the editor's - * control is created. If not, this editor uses a <code>SourceViewerConfiguration</code>. - * - * @param configuration the source viewer configuration object - */ - protected void setSourceViewerConfiguration(SourceViewerConfiguration configuration) { - Assert.isNotNull(configuration); - fConfiguration= configuration; - } - - /** - * Sets the annotation which this editor uses to represent the highlight - * range if the editor is configured to show the entire document. If the - * range indicator is not set, this editor uses a <code>DefaultRangeIndicator</code>. - * - * @param rangeIndicator the annotation - */ - protected void setRangeIndicator(Annotation rangeIndicator) { - Assert.isNotNull(rangeIndicator); - fRangeIndicator= rangeIndicator; - } - - /** - * Sets this editor's context menu id. - * - * @param contextMenuId the context menu id - */ - protected void setEditorContextMenuId(String contextMenuId) { - Assert.isNotNull(contextMenuId); - fEditorContextMenuId= contextMenuId; - } - - /** - * Sets the ruler's context menu id. - * - * @param contextMenuId the context menu id - */ - protected void setRulerContextMenuId(String contextMenuId) { - Assert.isNotNull(contextMenuId); - fRulerContextMenuId= contextMenuId; - } - - /** - * Sets the context menu registration 1.0 compatibility mode. (See class - * description for more details.) - * - * @param compatible <code>true</code> if compatibility mode is enabled - * @since 2.0 - */ - protected final void setCompatibilityMode(boolean compatible) { - fCompatibilityMode= compatible; - } - - /** - * Sets the editor's help context id. - * - * @param helpContextId the help context id - */ - protected void setHelpContextId(String helpContextId) { - Assert.isNotNull(helpContextId); - fHelpContextId= helpContextId; - } - - /** - * Sets this editor's preference store. This method must be - * called before the editor's control is created. - * - * @param store the new preference store - */ - protected void setPreferenceStore(IPreferenceStore store) { - if (fPreferenceStore != null) - fPreferenceStore.removePropertyChangeListener(fPropertyChangeListener); - - fPreferenceStore= store; - - if (fPreferenceStore != null) - fPreferenceStore.addPropertyChangeListener(fPropertyChangeListener); - } - - /* - * @see ITextEditor#isEditable - */ - public boolean isEditable() { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - return extension.isModifiable(getEditorInput()); - } - return false; - } - - /* - * @see ITextEditor#getSelectionProvider - */ - public ISelectionProvider getSelectionProvider() { - return fSelectionProvider; - } - - /** - * Remembers the current selection of this editor. This method is called when, e.g., - * the content of the editor is about to be reverted to the saved state. This method - * remembers the selection in a semantic format, i.e., in a format which allows to - * restore the selection even if the originally selected text is no longer part of the - * editor's content.<p> - * Subclasses should implement this method including all necessary state. This - * default implementation remembers the textual range only and is thus purely - * syntactic. - * - * @see #restoreSelection - * @since 2.0 - */ - protected void rememberSelection() { - fRememberedSelection= doGetSelection(); - } - - /** - * Returns the current selection. - * @return ISelection - */ - protected ISelection doGetSelection() { - ISelectionProvider sp= null; - if (fSourceViewer != null) - sp= fSourceViewer.getSelectionProvider(); - return (sp == null ? null : sp.getSelection()); - } - - /** - * Restores a selection previously remembered by <code>rememberSelection</code>. - * Subclasses may reimplement this method and thereby semantically adapt the - * remembered selection. This default implementation just selects the - * remembered textual range. - * - * @see #rememberSelection - * @since 2.0 - */ - protected void restoreSelection() { - doSetSelection(fRememberedSelection); - fRememberedSelection= null; - } - - /** - * Sets the given selection. - * @param selection - */ - protected void doSetSelection(ISelection selection) { - if (selection instanceof ITextSelection) { - ITextSelection textSelection= (ITextSelection) selection; - selectAndReveal(textSelection.getOffset(), textSelection.getLength()); - } - } - - /** - * Creates and returns the listener on this editor's context menus. - * - * @return the menu listener - */ - protected final IMenuListener getContextMenuListener() { - if (fMenuListener == null) { - fMenuListener= new IMenuListener() { - - public void menuAboutToShow(IMenuManager menu) { - String id= menu.getId(); - if (getRulerContextMenuId().equals(id)) { - setFocus(); - rulerContextMenuAboutToShow(menu); - } else if (getEditorContextMenuId().equals(id)) { - setFocus(); - editorContextMenuAboutToShow(menu); - } - } - }; - } - return fMenuListener; - } - - /** - * Creates and returns the listener on this editor's vertical ruler. - * - * @return the mouse listener - */ - protected final MouseListener getRulerMouseListener() { - if (fMouseListener == null) { - fMouseListener= new MouseListener() { - - private boolean fDoubleClicked= false; - - private void triggerAction(String actionID) { - IAction action= getAction(actionID); - if (action != null) { - if (action instanceof IUpdate) - ((IUpdate) action).update(); - if (action.isEnabled()) - action.run(); - } - } - - public void mouseUp(MouseEvent e) { - setFocus(); - if (1 == e.button && !fDoubleClicked) - triggerAction(ITextEditorActionConstants.RULER_CLICK); - fDoubleClicked= false; - } - - public void mouseDoubleClick(MouseEvent e) { - if (1 == e.button) { - fDoubleClicked= true; - triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK); - } - } - - public void mouseDown(MouseEvent e) { - StyledText text= fSourceViewer.getTextWidget(); - if (text != null && !text.isDisposed()) { - Display display= text.getDisplay(); - Point location= display.getCursorLocation(); - fRulerContextMenu.setLocation(location.x, location.y); - } - } - }; - } - return fMouseListener; - } - - /** - * Returns this editor's selection changed listener to be installed - * on the editor's source viewer. - * - * @return the listener - */ - protected final ISelectionChangedListener getSelectionChangedListener() { - if (fSelectionChangedListener == null) { - fSelectionChangedListener= new ISelectionChangedListener() { - - private Runnable fRunnable= new Runnable() { - public void run() { - // check whether editor has not been disposed yet - if (fSourceViewer != null) { - updateSelectionDependentActions(); - } - } - }; - - private Display fDisplay; - - public void selectionChanged(SelectionChangedEvent event) { - if (fDisplay == null) - fDisplay= getSite().getShell().getDisplay(); - fDisplay.asyncExec(fRunnable); - handleCursorPositionChanged(); - } - }; - } - - return fSelectionChangedListener; - } - - /** - * Returns this editor's "cursor" listener to be installed on the editor's - * source viewer. This listener is listening to key and mouse button events. - * It triggers the updating of the status line by calling - * <code>handleCursorPositionChanged()</code>. - * - * @return the listener - * @since 2.0 - */ - protected final ICursorListener getCursorListener() { - if (fCursorListener == null) { - fCursorListener= new ICursorListener() { - - public void keyPressed(KeyEvent e) { - } - - public void keyReleased(KeyEvent e) { - handleCursorPositionChanged(); - } - - public void mouseDoubleClick(MouseEvent e) { - } - - public void mouseDown(MouseEvent e) { - } - - public void mouseUp(MouseEvent e) { - handleCursorPositionChanged(); - } - }; - } - return fCursorListener; - } - - /* - * @see IEditorPart#init - */ - public void init(IEditorSite site, IEditorInput input) throws PartInitException { - - setSite(site); - - try { - doSetInput(input); - } catch (CoreException x) { - throw new PartInitException(x.getStatus()); - } - - IWorkbenchWindow window= getSite().getWorkbenchWindow(); - window.getPartService().addPartListener(fActivationListener); - window.getShell().addShellListener(fActivationListener); - } - - /** - * Creates the vertical ruler to be used by this editor. - * Subclasses may re-implement this method. - * - * @return the vertical ruler - */ - protected IVerticalRuler createVerticalRuler() { - return new VerticalRuler(VERTICAL_RULER_WIDTH); - } - - /** - * Creates the source viewer to be used by this editor. - * Subclasses may re-implement this method. - * - * @param parent the parent control - * @param ruler the vertical ruler - * @param styles style bits - * @return the source viewer - */ - protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { - return new SourceViewer(parent, ruler, styles); - } - - /** - * The <code>AbstractTextEditor</code> implementation of this - * <code>IWorkbenchPart</code> method creates the vertical ruler and - * source viewer. Subclasses may extend. - */ - public void createPartControl(Composite parent) { - - fVerticalRuler= createVerticalRuler(); - - int styles= SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION; - fSourceViewer= createSourceViewer(parent, fVerticalRuler, styles); - - if (fConfiguration == null) - fConfiguration= new SourceViewerConfiguration(); - fSourceViewer.configure(fConfiguration); - - if (fRangeIndicator != null) - fSourceViewer.setRangeIndicator(fRangeIndicator); - - fSourceViewer.addTextListener(fTextListener); - getSelectionProvider().addSelectionChangedListener(getSelectionChangedListener()); - - initializeViewerFont(fSourceViewer); - initializeViewerColors(fSourceViewer); - initializeFindScopeColor(fSourceViewer); - - StyledText styledText= fSourceViewer.getTextWidget(); - styledText.addMouseListener(getCursorListener()); - styledText.addKeyListener(getCursorListener()); - - if (getHelpContextId() != null) - WorkbenchHelp.setHelp(styledText, getHelpContextId()); - - - String id= fEditorContextMenuId != null ? fEditorContextMenuId : DEFAULT_EDITOR_CONTEXT_MENU_ID; - - MenuManager manager= new MenuManager(id, id); - manager.setRemoveAllWhenShown(true); - manager.addMenuListener(getContextMenuListener()); - fTextContextMenu= manager.createContextMenu(styledText); - styledText.setMenu(fTextContextMenu); - - if (fEditorContextMenuId != null) - getSite().registerContextMenu(fEditorContextMenuId, manager, getSelectionProvider()); - else if (fCompatibilityMode) - getSite().registerContextMenu(DEFAULT_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider()); - - if ((fEditorContextMenuId != null && fCompatibilityMode) || fEditorContextMenuId == null) { - String partId= getSite().getId(); - if (partId != null) - getSite().registerContextMenu(partId + ".EditorContext", manager, getSelectionProvider()); //$NON-NLS-1$ - } - - if (fEditorContextMenuId == null) - fEditorContextMenuId= DEFAULT_EDITOR_CONTEXT_MENU_ID; - - - id= fRulerContextMenuId != null ? fRulerContextMenuId : DEFAULT_RULER_CONTEXT_MENU_ID; - manager= new MenuManager(id, id); - manager.setRemoveAllWhenShown(true); - manager.addMenuListener(getContextMenuListener()); - - Control rulerControl= fVerticalRuler.getControl(); - fRulerContextMenu= manager.createContextMenu(rulerControl); - rulerControl.setMenu(fRulerContextMenu); - rulerControl.addMouseListener(getRulerMouseListener()); - - if (fRulerContextMenuId != null) - getSite().registerContextMenu(fRulerContextMenuId, manager, getSelectionProvider()); - else if (fCompatibilityMode) - getSite().registerContextMenu(DEFAULT_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider()); - - if ((fRulerContextMenuId != null && fCompatibilityMode) || fRulerContextMenuId == null) { - String partId= getSite().getId(); - if (partId != null) - getSite().registerContextMenu(partId + ".RulerContext", manager, getSelectionProvider()); //$NON-NLS-1$ - } - - if (fRulerContextMenuId == null) - fRulerContextMenuId= DEFAULT_RULER_CONTEXT_MENU_ID; - - getSite().setSelectionProvider(getSelectionProvider()); - - fActivationCodeTrigger.install(); - createNavigationActions(); - createAccessibilityActions(); - createActions(); - - initializeSourceViewer(getEditorInput()); - } - - /** - * Initializes the given viewer's font. - * - * @param viewer the viewer - * @since 2.0 - */ - private void initializeViewerFont(ISourceViewer viewer) { - - IPreferenceStore store= getPreferenceStore(); - if (store != null) { - - FontData data= null; - - if (store.contains(PREFERENCE_FONT) && !store.isDefault(PREFERENCE_FONT)) - data= PreferenceConverter.getFontData(store, PREFERENCE_FONT); - else - data= PreferenceConverter.getDefaultFontData(store, PREFERENCE_FONT); - - if (data != null) { - - Font font= new Font(viewer.getTextWidget().getDisplay(), data); - setFont(viewer, font); - - if (fFont != null) - fFont.dispose(); - - fFont= font; - return; - } - } - - // if all the preferences failed - setFont(viewer, JFaceResources.getTextFont()); - } - - /** - * Sets the font for the given viewer sustaining selection and scroll position. - * - * @param sourceViewer the source viewer - * @param font the font - * @since 2.0 - */ - private void setFont(ISourceViewer sourceViewer, Font font) { - if (sourceViewer.getDocument() != null) { - - Point selection= sourceViewer.getSelectedRange(); - int topIndex= sourceViewer.getTopIndex(); - - StyledText styledText= sourceViewer.getTextWidget(); - Control parent= styledText; - if (sourceViewer instanceof ITextViewerExtension) { - ITextViewerExtension extension= (ITextViewerExtension) sourceViewer; - parent= extension.getControl(); - } - - parent.setRedraw(false); - - styledText.setFont(font); - - if (fVerticalRuler instanceof IVerticalRulerExtension) { - IVerticalRulerExtension e= (IVerticalRulerExtension) fVerticalRuler; - e.setFont(font); - } - - sourceViewer.setSelectedRange(selection.x , selection.y); - sourceViewer.setTopIndex(topIndex); - - if (parent instanceof Composite) { - Composite composite= (Composite) parent; - composite.layout(true); - } - - parent.setRedraw(true); - - - } else { - - StyledText styledText= sourceViewer.getTextWidget(); - styledText.setFont(font); - - if (fVerticalRuler instanceof IVerticalRulerExtension) { - IVerticalRulerExtension e= (IVerticalRulerExtension) fVerticalRuler; - e.setFont(font); - } - } - } - - /** - * Creates a color from the information stored in the given preference store. - * Returns <code>null</code> if there is no such information available. - * - * @param store the store to read from - * @param key the key used for the lookup in the preference store - * @param display the display used create the color - * @return the created color according to the specification in the preference store - * @since 2.0 - */ - private Color createColor(IPreferenceStore store, String key, Display display) { - - RGB rgb= null; - - if (store.contains(key)) { - - if (store.isDefault(key)) - rgb= PreferenceConverter.getDefaultColor(store, key); - else - rgb= PreferenceConverter.getColor(store, key); - - if (rgb != null) - return new Color(display, rgb); - } - - return null; - } - - /** - * Initializes the given viewer's colors. - * - * @param viewer the viewer to be initialized - * @since 2.0 - */ - private void initializeViewerColors(ISourceViewer viewer) { - - IPreferenceStore store= getPreferenceStore(); - if (store != null) { - - StyledText styledText= viewer.getTextWidget(); - - // ----------- foreground color -------------------- - Color color= store.getBoolean(PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) - ? null - : createColor(store, PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); - styledText.setForeground(color); - - if (fForegroundColor != null) - fForegroundColor.dispose(); - - fForegroundColor= color; - - // ---------- background color ---------------------- - color= store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) - ? null - : createColor(store, PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); - styledText.setBackground(color); - - if (fBackgroundColor != null) - fBackgroundColor.dispose(); - - fBackgroundColor= color; - } - } - - /** - * Initializes the background color used for highlighting the document ranges - * defining search scopes. - * @param viewer the viewer to initialize - * @since 2.0 - */ - private void initializeFindScopeColor(ISourceViewer viewer) { - - IPreferenceStore store= getPreferenceStore(); - if (store != null) { - - StyledText styledText= viewer.getTextWidget(); - - Color color= createColor(store, PREFERENCE_COLOR_FIND_SCOPE, styledText.getDisplay()); - - IFindReplaceTarget target= viewer.getFindReplaceTarget(); - if (target != null && target instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) target).setScopeHighlightColor(color); - - if (fFindScopeHighlightColor != null) - fFindScopeHighlightColor.dispose(); - - fFindScopeHighlightColor= color; - } - } - - - /** - * Initializes the editor's source viewer based on the given editor input. - * - * @param input the editor input to be used to initialize the source viewer - */ - private void initializeSourceViewer(IEditorInput input) { - - IAnnotationModel model= getDocumentProvider().getAnnotationModel(input); - IDocument document= getDocumentProvider().getDocument(input); - - if (document != null) { - fSourceViewer.setDocument(document, model); - fSourceViewer.setEditable(isEditable()); - fSourceViewer.showAnnotations(model != null); - } - - if (fElementStateListener instanceof IElementStateListenerExtension) { - IElementStateListenerExtension extension= (IElementStateListenerExtension) fElementStateListener; - extension.elementStateValidationChanged(input, false); - } - } - - /** - * Initializes the editor's title based on the given editor input. - * - * @param input the editor input to be used - */ - private void initializeTitle(IEditorInput input) { - - Image oldImage= fTitleImage; - fTitleImage= null; - String title= ""; //$NON-NLS-1$ - - if (input != null) { - IEditorRegistry editorRegistry = getEditorSite().getPage().getWorkbenchWindow().getWorkbench().getEditorRegistry(); - IEditorDescriptor editorDesc= editorRegistry.findEditor(getSite().getId()); - ImageDescriptor imageDesc= editorDesc != null ? editorDesc.getImageDescriptor() : null; - - fTitleImage= imageDesc != null ? imageDesc.createImage() : null; - title= input.getName(); - } - - setTitleImage(fTitleImage); - setTitle(title); - - firePropertyChange(PROP_DIRTY); - - if (oldImage != null && !oldImage.isDisposed()) - oldImage.dispose(); - } - - /** - * If there is no implicit document provider set, the external one is - * re-initialized based on the given editor input. - * - * @param input the editor input. - */ - private void updateDocumentProvider(IEditorInput input) { - if (getDocumentProvider() != null) - getDocumentProvider().removeElementStateListener(fElementStateListener); - - if (fInternalDocumentProvider == null) - fExternalDocumentProvider= DocumentProviderRegistry.getDefault().getDocumentProvider(input); - - if (getDocumentProvider() != null) - getDocumentProvider().addElementStateListener(fElementStateListener); - } - - /** - * Internal <code>setInput</code> method. - * - * @param input the input to be set - * @exception CoreException if input cannot be connected to the document provider - */ - protected void doSetInput(IEditorInput input) throws CoreException { - - if (input == null) - - close(isSaveOnCloseNeeded()); - - else { - - IEditorInput oldInput= getEditorInput(); - if (oldInput != null) - getDocumentProvider().disconnect(oldInput); - - super.setInput(input); - - updateDocumentProvider(input); - - IDocumentProvider provider= getDocumentProvider(); - if (provider == null) { - IStatus s= new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, EditorMessages.getString("Editor.error.no_provider"), null); //$NON-NLS-1$ - throw new CoreException(s); - } - - provider.connect(input); - - initializeTitle(input); - if (fSourceViewer != null) - initializeSourceViewer(input); - - updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE); - } - } - - /* - * @see EditorPart#setInput - */ - public final void setInput(IEditorInput input) { - - try { - - doSetInput(input); - - } catch (CoreException x) { - String title= EditorMessages.getString("Editor.error.setinput.title"); //$NON-NLS-1$ - String msg= EditorMessages.getString("Editor.error.setinput.message"); //$NON-NLS-1$ - Shell shell= getSite().getShell(); - ErrorDialog.openError(shell, title, msg, x.getStatus()); - } - } - - /* - * @see ITextEditor#close - */ - public void close(final boolean save) { - - enableSanityChecking(false); - - Display display= getSite().getShell().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - if (fSourceViewer != null) { - // check whether editor has not been disposed yet - getSite().getPage().closeEditor(AbstractTextEditor.this, save); - } - } - }); - } - - /** - * The <code>AbstractTextEditor</code> implementation of this - * <code>IWorkbenchPart</code> method may be extended by subclasses. - * Subclasses must call <code>super.dispose()</code>. - */ - public void dispose() { - - if (fActivationListener != null) { - IWorkbenchWindow window= getSite().getWorkbenchWindow(); - window.getPartService().removePartListener(fActivationListener); - Shell shell= window.getShell(); - if (shell != null && !shell.isDisposed()) - shell.removeShellListener(fActivationListener); - fActivationListener= null; - } - - if (fTitleImage != null) { - fTitleImage.dispose(); - fTitleImage= null; - } - - if (fFont != null) { - fFont.dispose(); - fFont= null; - } - - if (fPropertyChangeListener != null) { - if (fPreferenceStore != null) { - fPreferenceStore.removePropertyChangeListener(fPropertyChangeListener); - fPreferenceStore= null; - } - fPropertyChangeListener= null; - } - - if (fActivationCodeTrigger != null) { - fActivationCodeTrigger.uninstall(); - fActivationCodeTrigger= null; - } - - IDocumentProvider provider= getDocumentProvider(); - if (provider != null) { - - IEditorInput input= getEditorInput(); - if (input != null) - provider.disconnect(input); - - if (fElementStateListener != null) { - provider.removeElementStateListener(fElementStateListener); - fElementStateListener= null; - } - - fInternalDocumentProvider= null; - fExternalDocumentProvider= null; - } - - if (fSourceViewer != null) { - - if (fTextListener != null) { - fSourceViewer.removeTextListener(fTextListener); - fTextListener= null; - } - - fSelectionProvider= null; - fSourceViewer= null; - } - - if (fTextContextMenu != null) { - fTextContextMenu.dispose(); - fTextContextMenu= null; - } - - if (fRulerContextMenu != null) { - fRulerContextMenu.dispose(); - fRulerContextMenu= null; - } - - if (fActions != null) { - fActions.clear(); - fActions= null; - } - - if (fSelectionActions != null) { - fSelectionActions.clear(); - fSelectionActions= null; - } - - if (fContentActions != null) { - fContentActions.clear(); - fContentActions= null; - } - - if (fPropertyActions != null) { - fPropertyActions.clear(); - fPropertyActions= null; - } - - if (fStateActions != null) { - fStateActions.clear(); - fStateActions= null; - } - - if (fActivationCodes != null) { - fActivationCodes.clear(); - fActivationCodes= null; - } - - if (fEditorStatusLine != null) - fEditorStatusLine= null; - - super.setInput(null); - - super.dispose(); - } - - /** - * Determines whether the given preference change affects the editor's - * presentation. This implementation always returns <code>false</code>. - * May be reimplemented by subclasses. - * - * @param event the event which should be investigated - * @return <code>true</code> if the event describes a preference change affecting the editor's presentation - * @since 2.0 - */ - protected boolean affectsTextPresentation(PropertyChangeEvent event) { - return false; - } - - /** - * Handles a property change event describing a change - * of the editor's preference store and updates the preference - * related editor properties. - * - * @param event the property change event - */ - protected void handlePreferenceStoreChanged(PropertyChangeEvent event) { - - if (fSourceViewer == null) - return; - - String property= event.getProperty(); - - if (PREFERENCE_FONT.equals(property)) { - initializeViewerFont(fSourceViewer); - - } else if (PREFERENCE_COLOR_FOREGROUND.equals(property) || PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || - PREFERENCE_COLOR_BACKGROUND.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)) - { - initializeViewerColors(fSourceViewer); - } else if (PREFERENCE_COLOR_FIND_SCOPE.equals(property)) { - initializeFindScopeColor(fSourceViewer); - } - - if (affectsTextPresentation(event)) - fSourceViewer.invalidateTextPresentation(); - } - - /** - * Handles an external change of the editor's input element. - */ - protected void handleEditorInputChanged() { - - String title; - String msg; - Shell shell= getSite().getShell(); - - IDocumentProvider provider= getDocumentProvider(); - if (provider == null) { - // fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=15066 - close(false); - return; - } - - IEditorInput input= getEditorInput(); - if (provider.isDeleted(input)) { - - if (isSaveAsAllowed()) { - - title= EditorMessages.getString("Editor.error.activated.deleted.save.title"); //$NON-NLS-1$ - msg= EditorMessages.getString("Editor.error.activated.deleted.save.message"); //$NON-NLS-1$ - - String[] buttons= { - EditorMessages.getString("Editor.error.activated.deleted.save.button.save"), //$NON-NLS-1$ - EditorMessages.getString("Editor.error.activated.deleted.save.button.close"), //$NON-NLS-1$ - }; - - MessageDialog dialog= new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0); - - if (dialog.open() == 0) { - NullProgressMonitor pm= new NullProgressMonitor(); - performSaveAs(pm); - if (pm.isCanceled()) - handleEditorInputChanged(); - } else { - close(false); - } - - } else { - - title= EditorMessages.getString("Editor.error.activated.deleted.close.title"); //$NON-NLS-1$ - msg= EditorMessages.getString("Editor.error.activated.deleted.close.message"); //$NON-NLS-1$ - if (MessageDialog.openConfirm(shell, title, msg)) - close(false); - } - - } else { - - title= EditorMessages.getString("Editor.error.activated.outofsync.title"); //$NON-NLS-1$ - msg= EditorMessages.getString("Editor.error.activated.outofsync.message"); //$NON-NLS-1$ - - if (MessageDialog.openQuestion(shell, title, msg)) { - try { - - if (provider instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - extension.synchronize(input); - } else { - doSetInput(input); - } - - - } catch (CoreException x) { - title= EditorMessages.getString("Editor.error.refresh.outofsync.title"); //$NON-NLS-1$ - msg= EditorMessages.getString("Editor.error.refresh.outofsync.message"); //$NON-NLS-1$ - ErrorDialog.openError(shell, title, msg, x.getStatus()); - } - } - -// // disabled because of http://bugs.eclipse.org/bugs/show_bug.cgi?id=15166 -// else { -// markEditorAsDirty(); -// } - - } - } - - /** - * Marks this editor and its editor input as dirty. - * @since 2.0 - */ - private void markEditorAsDirty() { - - if (isDirty()) - return; - - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IDocumentProviderExtension) { - - provider.removeElementStateListener(fElementStateListener); - try { - - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - extension.setCanSaveDocument(getEditorInput()); - firePropertyChange(PROP_DIRTY); - - } finally { - provider.addElementStateListener(fElementStateListener); - } - - } - } - - /** - * The <code>AbstractTextEditor</code> implementation of this - * <code>IEditorPart</code> method calls <code>oerformSaveAs</code>. - * Subclasses may reimplement. - */ - public void doSaveAs() { - /* - * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the editors. - * Changed Behavior to make sure that if called inside a regular save (because - * of deletion of input element) there is a way to report back to the caller. - */ - performSaveAs(new NullProgressMonitor()); - } - - /** - * Performs a save as and reports the result state back to the - * given progress monitor. This default implementation does nothing. - * Subclasses may reimplement. - * - * @param progressMonitor the progress monitor for communicating result state or <code>null</code> - */ - protected void performSaveAs(IProgressMonitor progressMonitor) { - } - - /** - * The <code>AbstractTextEditor</code> implementation of this - * <code>IEditorPart</code> method may be extended by subclasses. - */ - public void doSave(IProgressMonitor progressMonitor) { - - IDocumentProvider p= getDocumentProvider(); - if (p == null) - return; - - if (p.isDeleted(getEditorInput())) { - - if (isSaveAsAllowed()) { - - /* - * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the editors. - * Changed Behavior to make sure that if called inside a regular save (because - * of deletion of input element) there is a way to report back to the caller. - */ - performSaveAs(progressMonitor); - - } else { - - Shell shell= getSite().getShell(); - String title= EditorMessages.getString("Editor.error.save.deleted.title"); //$NON-NLS-1$ - String msg= EditorMessages.getString("Editor.error.save.deleted.message"); //$NON-NLS-1$ - MessageDialog.openError(shell, title, msg); - } - - } else { - - performSaveOperation(createSaveOperation(false), progressMonitor); - } - } - - /** - * Enables/Disabled sanity checking. - * @param enable <code>true</code> if santity checking should be enabled, <code>false</code> otherwise - * @since 2.0 - */ - protected void enableSanityChecking(boolean enable) { - synchronized (this) { - fIsSanityCheckEnabled= enable; - } - } - - /** - * Checks the state of the given editor input if sanity checking is enabled. - * @param input the editor input whose state is to be checked - * @since 2.0 - */ - protected void safelySanityCheckState(IEditorInput input) { - boolean enabled= false; - - synchronized (this) { - enabled= fIsSanityCheckEnabled; - } - - if (enabled) - sanityCheckState(input); - } - - /** - * Checks the state of the given editor input. - * @param input the editor input whose state is to be checked - * @since 2.0 - */ - protected void sanityCheckState(IEditorInput input) { - - IDocumentProvider p= getDocumentProvider(); - if (p == null) - return; - - if (fModificationStamp == -1) - fModificationStamp= p.getSynchronizationStamp(input); - - long stamp= p.getModificationStamp(input); - if (stamp != fModificationStamp) { - fModificationStamp= stamp; - if (stamp != p.getSynchronizationStamp(input)) - handleEditorInputChanged(); - } - - updateState(getEditorInput()); - updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE); - } - - /** - * Validates the state of the given editor input. The predominate intent - * of this method is to take any action propably necessary to ensure that - * the input can persistently be changed. - * - * @param input the input to be validated - * @since 2.0 - */ - protected void validateState(IEditorInput input) { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - try { - - boolean wasReadOnly= isEditorInputReadOnly(); - - extension.validateState(input, getSite().getShell()); - - if (fSourceViewer != null) - fSourceViewer.setEditable(isEditable()); - - if (wasReadOnly != isEditorInputReadOnly()) - updateStateDependentActions(); - - } catch (CoreException x) { - ILog log= Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog(); - log.log(x.getStatus()); - } - } - } - - /** - * Updates the state of the given editor input such as read-only flag etc. - * - * @param input the input to be validated - * @since 2.0 - */ - protected void updateState(IEditorInput input) { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - try { - - boolean wasReadOnly= isEditorInputReadOnly(); - extension.updateStateCache(input); - - if (fSourceViewer != null) - fSourceViewer.setEditable(isEditable()); - - if (wasReadOnly != isEditorInputReadOnly()) - updateStateDependentActions(); - - } catch (CoreException x) { - ILog log= Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog(); - log.log(x.getStatus()); - } - } - } - - /** - * Creates a workspace modify operation which saves the content of the editor - * to the editor's input element. <code>overwrite</code> indicates whether - * the editor input element may be overwritten if necessary. Clients may - * reimplement this method. - * - * @param overwrite indicates whether or not overwrititng is allowed - * @return the save operation - */ - protected WorkspaceModifyOperation createSaveOperation(final boolean overwrite) { - return new WorkspaceModifyOperation() { - public void execute(final IProgressMonitor monitor) throws CoreException { - IEditorInput input= getEditorInput(); - getDocumentProvider().saveDocument(monitor, input, getDocumentProvider().getDocument(input), overwrite); - } - }; - } - - /** - * Performs the given save operation and handles errors appropriatly. - * - * @param operation the operation to be performed - * @param progressMonitor the monitor in which to run the operation - */ - protected void performSaveOperation(WorkspaceModifyOperation operation, IProgressMonitor progressMonitor) { - - IDocumentProvider provider= getDocumentProvider(); - - try { - - provider.aboutToChange(getEditorInput()); - operation.run(progressMonitor); - editorSaved(); - - } catch (InterruptedException x) { - } catch (InvocationTargetException x) { - - Throwable t= x.getTargetException(); - if (t instanceof CoreException) - handleExceptionOnSave((CoreException) t, progressMonitor); - else { - Shell shell= getSite().getShell(); - String title= EditorMessages.getString("Editor.error.save.title"); //$NON-NLS-1$ - String msg= EditorMessages.getString("Editor.error.save.message"); //$NON-NLS-1$ - MessageDialog.openError(shell, title, msg + t.getMessage()); - } - - } finally { - provider.changed(getEditorInput()); - } - } - - /** - * Handles the given exception. If the exception reports an out-of-sync - * situation, this is reported to the user. Otherwise, the exception - * is generically reported. - * - * @param exception the exception to handle - * @param progressMonitor the progress monitor - */ - protected void handleExceptionOnSave(CoreException exception, IProgressMonitor progressMonitor) { - - try { - ++ fErrorCorrectionOnSave; - - Shell shell= getSite().getShell(); - - IDocumentProvider p= getDocumentProvider(); - long modifiedStamp= p.getModificationStamp(getEditorInput()); - long synchStamp= p.getSynchronizationStamp(getEditorInput()); - - if (fErrorCorrectionOnSave == 1 && modifiedStamp != synchStamp) { - - String title= EditorMessages.getString("Editor.error.save.outofsync.title"); //$NON-NLS-1$ - String msg= EditorMessages.getString("Editor.error.save.outofsync.message"); //$NON-NLS-1$ - - if (MessageDialog.openQuestion(shell, title, msg)) - performSaveOperation(createSaveOperation(true), progressMonitor); - else { - /* - * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits - * Set progress monitor to canceled in order to report back - * to enclosing operations. - */ - if (progressMonitor != null) - progressMonitor.setCanceled(true); - } - } else { - - String title= EditorMessages.getString("Editor.error.save.title"); //$NON-NLS-1$ - String msg= EditorMessages.getString("Editor.error.save.message"); //$NON-NLS-1$ - ErrorDialog.openError(shell, title, msg, exception.getStatus()); - - /* - * 1GEUPKR: ITPJUI:ALL - Loosing work with simultaneous edits - * Set progress monitor to canceled in order to report back - * to enclosing operations. - */ - if (progressMonitor != null) - progressMonitor.setCanceled(true); - } - - } finally { - -- fErrorCorrectionOnSave; - } - } - - /** - * The <code>AbstractTextEditor</code> implementation of this - * <code>IEditorPart</code> method returns <code>false</code>. Subclasses - * may override. - */ - public boolean isSaveAsAllowed() { - return false; - } - - /* - * @see IEditorPart#isSaveOnCloseNeeded() - */ - public boolean isSaveOnCloseNeeded() { - IDocumentProvider p= getDocumentProvider(); - return p == null ? false : p.mustSaveDocument(getEditorInput()); - } - - /* - * @see IEditorPart#isDirty - */ - public boolean isDirty() { - IDocumentProvider p= getDocumentProvider(); - return p == null ? false : p.canSaveDocument(getEditorInput()); - } - - /** - * The <code>AbstractTextEditor</code> implementation of this - * <code>ITextEditor</code> method may be extended by subclasses. - */ - public void doRevertToSaved() { - - IDocumentProvider p= getDocumentProvider(); - if (p == null) - return; - - try { - - p.resetDocument(getEditorInput()); - - IAnnotationModel model= p.getAnnotationModel(getEditorInput()); - if (model instanceof AbstractMarkerAnnotationModel) { - AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model; - markerModel.resetMarkers(); - } - - firePropertyChange(PROP_DIRTY); - - } catch (CoreException x) { - String title= EditorMessages.getString("Editor.error.revert.title"); //$NON-NLS-1$ - String msg= EditorMessages.getString("Editor.error.revert.message"); //$NON-NLS-1$ - Shell shell= getSite().getShell(); - ErrorDialog.openError(shell, title, msg, x.getStatus()); - } - } - - /* - * @see ITextEditor#setAction - */ - public void setAction(String actionID, IAction action) { - Assert.isNotNull(actionID); - if (action == null) { - action= (IAction) fActions.remove(actionID); - if (action != null) - fActivationCodeTrigger.unregisterActionFromKeyActivation(action); - } else { - fActions.put(actionID, action); - fActivationCodeTrigger.registerActionForKeyActivation(action); - } - } - - /* - * @see ITextEditor#setActionActivationCode(String, char, int, int) - */ - public void setActionActivationCode(String actionID, char activationCharacter, int activationKeyCode, int activationStateMask) { - - Assert.isNotNull(actionID); - - ActionActivationCode found= findActionActivationCode(actionID); - if (found == null) { - found= new ActionActivationCode(actionID); - fActivationCodes.add(found); - } - - found.fCharacter= activationCharacter; - found.fKeyCode= activationKeyCode; - found.fStateMask= activationStateMask; - } - - /** - * Returns the activation code registered for the specified action. - * - * @param actionID the action id - * @return the registered activation code or <code>null</code> if no code has been installed - */ - private ActionActivationCode findActionActivationCode(String actionID) { - int size= fActivationCodes.size(); - for (int i= 0; i < size; i++) { - ActionActivationCode code= (ActionActivationCode) fActivationCodes.get(i); - if (actionID.equals(code.fActionId)) - return code; - } - return null; - } - - /* - * @see ITextEditor#removeActionActivationCode(String) - */ - public void removeActionActivationCode(String actionID) { - Assert.isNotNull(actionID); - ActionActivationCode code= findActionActivationCode(actionID); - if (code != null) - fActivationCodes.remove(code); - } - - /* - * @see ITextEditor#getAction - */ - public IAction getAction(String actionID) { - Assert.isNotNull(actionID); - IAction action= (IAction) fActions.get(actionID); - - if (action == null) { - action= findContributedAction(actionID); - if (action != null) - setAction(actionID, action); - } - - return action; - } - - /** - * Returns the action with the given action id that has been contributed via xml to this editor. - * The lookup honors the dependencies of plugins. - * - * @param actionID the action id to look up - * @return the action that has been contributed - * @since 2.0 - */ - private IAction findContributedAction(String actionID) { - IExtensionPoint extensionPoint= Platform.getPluginRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, "editorActions"); //$NON-NLS-1$ - if (extensionPoint != null) { - IConfigurationElement[] elements= extensionPoint.getConfigurationElements(); - - List actions= new ArrayList(); - for (int i= 0; i < elements.length; i++) { - IConfigurationElement element= elements[i]; - if (TAG_CONTRIBUTION_TYPE.equals(element.getName())) { - if (!getSite().getId().equals(element.getAttribute("targetID"))) //$NON-NLS-1$ - continue; - - IConfigurationElement[] children= element.getChildren("action"); //$NON-NLS-1$ - for (int j= 0; j < children.length; j++) { - IConfigurationElement child= children[j]; - if (actionID.equals(child.getAttribute("actionID"))) //$NON-NLS-1$ - actions.add(child); - } - } - } - Collections.sort(actions, new ConfigurationElementComparator()); - - if (actions.size() != 0) { - IConfigurationElement element= (IConfigurationElement) actions.get(0); - return new EditorPluginAction(element, "class", this); //$NON-NLS-1$ - } - } - - return null; - } - - /** - * Updates the specified action by calling <code>IUpdate.update</code> - * if applicable. - * - * @param actionId the action id - */ - private void updateAction(String actionId) { - Assert.isNotNull(actionId); - if (fActions != null) { - IAction action= (IAction) fActions.get(actionId); - if (action instanceof IUpdate) - ((IUpdate) action).update(); - } - } - - /** - * Marks or unmarks the given action to be updated on text selection changes. - * - * @param actionId the action id - * @param mark <code>true</code> if the action is selection dependent - */ - public void markAsSelectionDependentAction(String actionId, boolean mark) { - Assert.isNotNull(actionId); - if (mark) { - if (!fSelectionActions.contains(actionId)) - fSelectionActions.add(actionId); - } else - fSelectionActions.remove(actionId); - } - - /** - * Marks or unmarks the given action to be updated on content changes. - * - * @param actionId the action id - * @param mark <code>true</code> if the action is content dependent - */ - public void markAsContentDependentAction(String actionId, boolean mark) { - Assert.isNotNull(actionId); - if (mark) { - if (!fContentActions.contains(actionId)) - fContentActions.add(actionId); - } else - fContentActions.remove(actionId); - } - - /** - * Marks or unmarks the given action to be updated on property changes. - * - * @param actionId the action id - * @param mark <code>true</code> if the action is property dependent - * @since 2.0 - */ - public void markAsPropertyDependentAction(String actionId, boolean mark) { - Assert.isNotNull(actionId); - if (mark) { - if (!fPropertyActions.contains(actionId)) - fPropertyActions.add(actionId); - } else - fPropertyActions.remove(actionId); - } - - /** - * Marks or unmarks the given action to be updated on state changes. - * - * @param actionId the action id - * @param mark <code>true</code> if the action is state dependent - * @since 2.0 - */ - public void markAsStateDependentAction(String actionId, boolean mark) { - Assert.isNotNull(actionId); - if (mark) { - if (!fStateActions.contains(actionId)) - fStateActions.add(actionId); - } else - fStateActions.remove(actionId); - } - - /** - * Updates all selection dependent actions. - */ - protected void updateSelectionDependentActions() { - if (fSelectionActions != null) { - Iterator e= fSelectionActions.iterator(); - while (e.hasNext()) - updateAction((String) e.next()); - } - } - - /** - * Updates all content dependent actions. - */ - protected void updateContentDependentActions() { - if (fContentActions != null) { - Iterator e= fContentActions.iterator(); - while (e.hasNext()) - updateAction((String) e.next()); - } - } - - /** - * Updates all property dependent actions. - * @since 2.0 - */ - protected void updatePropertyDependentActions() { - if (fPropertyActions != null) { - Iterator e= fPropertyActions.iterator(); - while (e.hasNext()) - updateAction((String) e.next()); - } - } - - /** - * Updates all state dependent actions. - * @since 2.0 - */ - protected void updateStateDependentActions() { - if (fStateActions != null) { - Iterator e= fStateActions.iterator(); - while (e.hasNext()) - updateAction((String) e.next()); - } - } - - /** - * Creates this editor's standard navigation actions. - * <p> - * Subclasses may extend. - * </p> - * @since 2.0 - */ - protected void createNavigationActions() { - - IAction action; - - StyledText textWidget= getSourceViewer().getTextWidget(); - for (int i= 0; i < ACTION_MAP.length; i++) { - IdMapEntry entry= (IdMapEntry) ACTION_MAP[i]; - action= new TextNavigationAction(textWidget, entry.getAction()); - action.setActionDefinitionId(entry.getActionId()); - setAction(entry.getActionId(), action); - } - - action= new ToggleInsertModeAction(textWidget); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE); - setAction(ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE, action); - - action= new ScrollLinesAction(-1); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SCROLL_LINE_UP); - setAction(ITextEditorActionDefinitionIds.SCROLL_LINE_UP, action); - - action= new ScrollLinesAction(1); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SCROLL_LINE_DOWN); - setAction(ITextEditorActionDefinitionIds.SCROLL_LINE_DOWN, action); - } - - /** - * Creates this editor's accessibility actions. - * @since 2.0 - */ - private void createAccessibilityActions() { - IAction action= new ShowRulerContextMenuAction(); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_RULER_CONTEXT_MENU); - setAction(ITextEditorActionDefinitionIds.SHOW_RULER_CONTEXT_MENU, action); - } - - /** - * Creates this editor's standard actions and connects them with the global - * workbench actions. - * <p> - * Subclasses may extend. - * </p> - */ - protected void createActions() { - - ResourceAction action; - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Undo.", this, ITextOperationTarget.UNDO); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.UNDO_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.UNDO); - setAction(ITextEditorActionConstants.UNDO, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Redo.", this, ITextOperationTarget.REDO); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.REDO_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.REDO); - setAction(ITextEditorActionConstants.REDO, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Cut.", this, ITextOperationTarget.CUT); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.CUT_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.CUT); - setAction(ITextEditorActionConstants.CUT, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Copy.", this, ITextOperationTarget.COPY, true); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.COPY_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.COPY); - setAction(ITextEditorActionConstants.COPY, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Paste.", this, ITextOperationTarget.PASTE); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.PASTE_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.PASTE); - setAction(ITextEditorActionConstants.PASTE, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Delete.", this, ITextOperationTarget.DELETE); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.DELETE_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE); - setAction(ITextEditorActionConstants.DELETE, action); - - action= new DeleteLineAction(EditorMessages.getResourceBundle(), "Editor.DeleteLine.", this, DeleteLineAction.WHOLE); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.DELETE_LINE_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_LINE); - setAction(ITextEditorActionConstants.DELETE_LINE, action); - - action= new DeleteLineAction(EditorMessages.getResourceBundle(), "Editor.DeleteLineToBeginning.", this, DeleteLineAction.TO_BEGINNING); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.DELETE_LINE_TO_BEGINNING_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_LINE_TO_BEGINNING); - setAction(ITextEditorActionConstants.DELETE_LINE_TO_BEGINNING, action); - - action= new DeleteLineAction(EditorMessages.getResourceBundle(), "Editor.DeleteLineToEnd.", this, DeleteLineAction.TO_END); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.DELETE_LINE_TO_END_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.DELETE_LINE_TO_END); - setAction(ITextEditorActionConstants.DELETE_LINE_TO_END, action); - - action= new MarkAction(EditorMessages.getResourceBundle(), "Editor.SetMark.", this, MarkAction.SET_MARK); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.SET_MARK_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SET_MARK); - setAction(ITextEditorActionConstants.SET_MARK, action); - - action= new MarkAction(EditorMessages.getResourceBundle(), "Editor.ClearMark.", this, MarkAction.CLEAR_MARK); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.CLEAR_MARK_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.CLEAR_MARK); - setAction(ITextEditorActionConstants.CLEAR_MARK, action); - - action= new MarkAction(EditorMessages.getResourceBundle(), "Editor.SwapMark.", this, MarkAction.SWAP_MARK); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.SWAP_MARK_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SWAP_MARK); - setAction(ITextEditorActionConstants.SWAP_MARK, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.SelectAll.", this, ITextOperationTarget.SELECT_ALL, true); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.SELECT_ALL_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_ALL); - setAction(ITextEditorActionConstants.SELECT_ALL, action); - - action= new ShiftAction(EditorMessages.getResourceBundle(), "Editor.ShiftRight.", this, ITextOperationTarget.SHIFT_RIGHT); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_RIGHT_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_RIGHT); - setAction(ITextEditorActionConstants.SHIFT_RIGHT, action); - - action= new ShiftAction(EditorMessages.getResourceBundle(), "Editor.ShiftLeft.", this, ITextOperationTarget.SHIFT_LEFT); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.SHIFT_LEFT_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHIFT_LEFT); - setAction(ITextEditorActionConstants.SHIFT_LEFT, action); - - action= new TextOperationAction(EditorMessages.getResourceBundle(), "Editor.Print.", this, ITextOperationTarget.PRINT, true); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.PRINT_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.PRINT); - setAction(ITextEditorActionConstants.PRINT, action); - - action= new FindReplaceAction(EditorMessages.getResourceBundle(), "Editor.FindReplace.", this); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.FIND_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.FIND_REPLACE); - setAction(ITextEditorActionConstants.FIND, action); - - action= new FindNextAction(EditorMessages.getResourceBundle(), "Editor.FindNext.", this, true); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.FIND_NEXT_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.FIND_NEXT); - setAction(ITextEditorActionConstants.FIND_NEXT, action); - - action= new FindNextAction(EditorMessages.getResourceBundle(), "Editor.FindPrevious.", this, false); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.FIND_PREVIOUS_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.FIND_PREVIOUS); - setAction(ITextEditorActionConstants.FIND_PREVIOUS, action); - - action= new IncrementalFindAction(EditorMessages.getResourceBundle(), "Editor.FindIncremental.", this, true); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.FIND_INCREMENTAL_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.FIND_INCREMENTAL); - setAction(ITextEditorActionConstants.FIND_INCREMENTAL, action); - - action= new IncrementalFindAction(EditorMessages.getResourceBundle(), "Editor.FindIncrementalReverse.", this, false); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.FIND_INCREMENTAL_REVERSE_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.FIND_INCREMENTAL_REVERSE); - setAction(ITextEditorActionConstants.FIND_INCREMENTAL_REVERSE, action); - - action= new AddMarkerAction(EditorMessages.getResourceBundle(), "Editor.AddBookmark.", this, IMarker.BOOKMARK, true); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.BOOKMARK_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.ADD_BOOKMARK); - setAction(ITextEditorActionConstants.BOOKMARK, action); - -// FIXME: need another way to contribute this action -// action= new AddTaskAction(EditorMessages.getResourceBundle(), "Editor.AddTask.", this); //$NON-NLS-1$ -// action.setHelpContextId(IAbstractTextEditorHelpContextIds.ADD_TASK_ACTION); -// action.setActionDefinitionId(ITextEditorActionDefinitionIds.ADD_TASK); -// setAction(ITextEditorActionConstants.ADD_TASK, action); - - action= new SaveAction(EditorMessages.getResourceBundle(), "Editor.Save.", this); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.SAVE_ACTION); - // action.setActionDefinitionId(ITextEditorActionDefinitionIds.SAVE); - setAction(ITextEditorActionConstants.SAVE, action); - - action= new RevertToSavedAction(EditorMessages.getResourceBundle(), "Editor.Revert.", this); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.REVERT_TO_SAVED_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.REVERT_TO_SAVED); - setAction(ITextEditorActionConstants.REVERT_TO_SAVED, action); - - action= new GotoLineAction(EditorMessages.getResourceBundle(), "Editor.GotoLine.", this); //$NON-NLS-1$ - action.setHelpContextId(IAbstractTextEditorHelpContextIds.GOTO_LINE_ACTION); - action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_GOTO); - setAction(ITextEditorActionConstants.GOTO_LINE, action); - - markAsContentDependentAction(ITextEditorActionConstants.UNDO, true); - markAsContentDependentAction(ITextEditorActionConstants.REDO, true); - markAsContentDependentAction(ITextEditorActionConstants.FIND, true); - markAsContentDependentAction(ITextEditorActionConstants.FIND_NEXT, true); - markAsContentDependentAction(ITextEditorActionConstants.FIND_PREVIOUS, true); - markAsContentDependentAction(ITextEditorActionConstants.FIND_INCREMENTAL, true); - markAsContentDependentAction(ITextEditorActionConstants.FIND_INCREMENTAL_REVERSE, true); - - markAsSelectionDependentAction(ITextEditorActionConstants.CUT, true); - markAsSelectionDependentAction(ITextEditorActionConstants.COPY, true); - markAsSelectionDependentAction(ITextEditorActionConstants.PASTE, true); - markAsSelectionDependentAction(ITextEditorActionConstants.DELETE, true); - markAsSelectionDependentAction(ITextEditorActionConstants.SHIFT_RIGHT, true); - markAsSelectionDependentAction(ITextEditorActionConstants.SHIFT_LEFT, true); - - markAsPropertyDependentAction(ITextEditorActionConstants.REVERT_TO_SAVED, true); - - markAsStateDependentAction(ITextEditorActionConstants.UNDO, true); - markAsStateDependentAction(ITextEditorActionConstants.REDO, true); - markAsStateDependentAction(ITextEditorActionConstants.CUT, true); - markAsStateDependentAction(ITextEditorActionConstants.PASTE, true); - markAsStateDependentAction(ITextEditorActionConstants.DELETE, true); - markAsStateDependentAction(ITextEditorActionConstants.SHIFT_RIGHT, true); - markAsStateDependentAction(ITextEditorActionConstants.SHIFT_LEFT, true); - markAsStateDependentAction(ITextEditorActionConstants.FIND, true); - markAsStateDependentAction(ITextEditorActionConstants.DELETE_LINE, true); - markAsStateDependentAction(ITextEditorActionConstants.DELETE_LINE_TO_BEGINNING, true); - markAsStateDependentAction(ITextEditorActionConstants.DELETE_LINE_TO_END, true); - - setActionActivationCode(ITextEditorActionConstants.SHIFT_RIGHT,'\t', -1, SWT.NONE); - setActionActivationCode(ITextEditorActionConstants.SHIFT_LEFT, '\t', -1, SWT.SHIFT); - } - - /** - * Convenience method to add the action installed under the given action id to the given menu. - * @param menu the menu to add the action to - * @param actionId the id of the action to be added - */ - protected final void addAction(IMenuManager menu, String actionId) { - IAction action= getAction(actionId); - if (action != null) { - if (action instanceof IUpdate) - ((IUpdate) action).update(); - menu.add(action); - } - } - - /** - * Convenience method to add the action installed under the given action id to the specified group of the menu. - * @param menu the menu to add the action to - * @param group the group in the menu - * @param actionId the id of the action to add - */ - protected final void addAction(IMenuManager menu, String group, String actionId) { - IAction action= getAction(actionId); - if (action != null) { - if (action instanceof IUpdate) - ((IUpdate) action).update(); - - IMenuManager subMenu= menu.findMenuUsingPath(group); - if (subMenu != null) - subMenu.add(action); - else - menu.appendToGroup(group, action); - } - } - - /** - * Convenience method to add a new group after the specified group. - * @param menu the menu to add the new group to - * @param existingGroup the group after which to insert the new group - * @param newGroup the new group - */ - protected final void addGroup(IMenuManager menu, String existingGroup, String newGroup) { - IMenuManager subMenu= menu.findMenuUsingPath(existingGroup); - if (subMenu != null) - subMenu.add(new Separator(newGroup)); - else - menu.appendToGroup(existingGroup, new Separator(newGroup)); - } - - /** - * Sets up the ruler context menu before it is made visible. - * <p> - * Subclasses may extend to add other actions. - * </p> - * - * @param menu the menu - */ - protected void rulerContextMenuAboutToShow(IMenuManager menu) { - - for (Iterator i = fRulerContextMenuListeners.iterator(); i.hasNext();) - ((IMenuListener) i.next()).menuAboutToShow(menu); - - addAction(menu, ITextEditorActionConstants.RULER_MANAGE_BOOKMARKS); - addAction(menu, ITextEditorActionConstants.RULER_MANAGE_TASKS); - - menu.add(new Separator(ITextEditorActionConstants.GROUP_REST)); - menu.add(new Separator(ITextEditorActionConstants.MB_ADDITIONS)); - } - - /** - * Sets up this editor's context menu before it is made visible. - * <p> - * Subclasses may extend to add other actions. - * </p> - * - * @param menu the menu - */ - protected void editorContextMenuAboutToShow(IMenuManager menu) { - - menu.add(new Separator(ITextEditorActionConstants.GROUP_UNDO)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_COPY)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_PRINT)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_FIND)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_ADD)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_REST)); - menu.add(new Separator(ITextEditorActionConstants.MB_ADDITIONS)); - menu.add(new Separator(ITextEditorActionConstants.GROUP_SAVE)); - - if (isEditable()) { - addAction(menu, ITextEditorActionConstants.GROUP_UNDO, ITextEditorActionConstants.UNDO); - addAction(menu, ITextEditorActionConstants.GROUP_UNDO, ITextEditorActionConstants.REVERT_TO_SAVED); - addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.CUT); - addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.COPY); - addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.PASTE); - addAction(menu, ITextEditorActionConstants.GROUP_SAVE, ITextEditorActionConstants.SAVE); - } else { - addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.COPY); - } - } - - /** - * Returns the status line manager of this editor. - * @return the status line manager of this editor - * @since 2.0 - */ - private IStatusLineManager getStatusLineManager() { - - IEditorActionBarContributor contributor= getEditorSite().getActionBarContributor(); - if (!(contributor instanceof EditorActionBarContributor)) - return null; - - IActionBars actionBars= ((EditorActionBarContributor) contributor).getActionBars(); - if (actionBars == null) - return null; - - return actionBars.getStatusLineManager(); - } - - /* - * @see IAdaptable#getAdapter(Class) - */ - public Object getAdapter(Class required) { - - if (IEditorStatusLine.class.equals(required)) { - if (fEditorStatusLine == null) { - IStatusLineManager statusLineManager= getStatusLineManager(); - ISelectionProvider selectionProvider= getSelectionProvider(); - if (statusLineManager != null && selectionProvider != null) - fEditorStatusLine= new EditorStatusLine(statusLineManager, selectionProvider); - } - return fEditorStatusLine; - } - - if (IVerticalRulerInfo.class.equals(required)) { - if (fVerticalRuler instanceof IVerticalRulerInfo) - return fVerticalRuler; - } - - if (IMarkRegionTarget.class.equals(required)) { - if (fMarkRegionTarget == null) { - IStatusLineManager manager= getStatusLineManager(); - if (manager != null) - fMarkRegionTarget= (fSourceViewer == null ? null : new MarkRegionTarget(fSourceViewer, manager)); - } - return fMarkRegionTarget; - } - - if (DeleteLineTarget.class.equals(required)){ - if (fDeleteLineTarget == null) { - fDeleteLineTarget = new DeleteLineTarget(fSourceViewer); - } - return fDeleteLineTarget; - } - - if (IncrementalFindTarget.class.equals(required)) { - if (fIncrementalFindTarget == null) { - IStatusLineManager manager= getStatusLineManager(); - if (manager != null) - fIncrementalFindTarget= (fSourceViewer == null ? null : new IncrementalFindTarget(fSourceViewer, manager)); - } - return fIncrementalFindTarget; - } - - if (IFindReplaceTarget.class.equals(required)) { - IFindReplaceTarget target= (fSourceViewer == null ? null : fSourceViewer.getFindReplaceTarget()); - if (target != null && target instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) target).setScopeHighlightColor(fFindScopeHighlightColor); - return target; - } - - if (ITextOperationTarget.class.equals(required)) - return (fSourceViewer == null ? null : fSourceViewer.getTextOperationTarget()); - - if (IRewriteTarget.class.equals(required)) { - if (fSourceViewer instanceof ITextViewerExtension) { - ITextViewerExtension extension= (ITextViewerExtension) fSourceViewer; - return extension.getRewriteTarget(); - } - return null; - } - - return super.getAdapter(required); - } - - /* - * @see IDesktopPart#setFocus() - */ - public void setFocus() { - if (fSourceViewer != null && fSourceViewer.getTextWidget() != null) - fSourceViewer.getTextWidget().setFocus(); - } - - /** - * If the editor can be saved all marker ranges have been changed according to - * the text manipulations. However, those changes are not yet propagated to the - * marker manager. Thus, when opening a marker, the marker's position in the editor - * must be determined as it might differ from the position stated in the marker. - * @param marker the marker to go to - * @see EditorPart#gotoMarker - */ - public void gotoMarker(IMarker marker) { - - if (fSourceViewer == null) - return; - - int start= MarkerUtilities.getCharStart(marker); - int end= MarkerUtilities.getCharEnd(marker); - - if (start < 0 || end < 0) { - - // there is only a line number - int line= MarkerUtilities.getLineNumber(marker); - if (line > -1) { - - // marker line numbers are 1-based - -- line; - - try { - - IDocument document= getDocumentProvider().getDocument(getEditorInput()); - selectAndReveal(document.getLineOffset(line), document.getLineLength(line)); - - } catch (BadLocationException x) { - // marker refers to invalid text position -> do nothing - } - } - - } else { - - // look up the current range of the marker when the document has been edited - IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput()); - if (model instanceof AbstractMarkerAnnotationModel) { - - AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model; - Position pos= markerModel.getMarkerPosition(marker); - if (pos == null || pos.isDeleted()) { - // do nothing if position has been deleted - return; - } - - start= pos.getOffset(); - end= pos.getOffset() + pos.getLength(); - } - - IDocument document= getDocumentProvider().getDocument(getEditorInput()); - int length= document.getLength(); - if (end - 1 < length && start < length) - selectAndReveal(start, end - start); - } - } - - /* - * @see ITextEditor#showsHighlightRangeOnly - */ - public boolean showsHighlightRangeOnly() { - return fShowHighlightRangeOnly; - } - - /* - * @see ITextEditor#showHighlightRangeOnly - */ - public void showHighlightRangeOnly(boolean showHighlightRangeOnly) { - fShowHighlightRangeOnly= showHighlightRangeOnly; - } - - /* - * @see ITextEditor#setHighlightRange - */ - public void setHighlightRange(int start, int length, boolean moveCursor) { - if (fSourceViewer == null) - return; - - if (fShowHighlightRangeOnly) { - if (moveCursor) { - IRegion visibleRegion= fSourceViewer.getVisibleRegion(); - if (start != visibleRegion.getOffset() || length != visibleRegion.getLength()) - fSourceViewer.setVisibleRegion(start, length); - } - } else { - IRegion rangeIndication= fSourceViewer.getRangeIndication(); - if (rangeIndication == null || start != rangeIndication.getOffset() || length != rangeIndication.getLength()) - fSourceViewer.setRangeIndication(start, length, moveCursor); - } - } - - /* - * @see ITextEditor#getHighlightRange - */ - public IRegion getHighlightRange() { - if (fSourceViewer == null) - return null; - - if (fShowHighlightRangeOnly) - return fSourceViewer.getVisibleRegion(); - - return fSourceViewer.getRangeIndication(); - } - - /* - * @see ITextEditor#resetHighlightRange - */ - public void resetHighlightRange() { - if (fSourceViewer == null) - return; - - if (fShowHighlightRangeOnly) - fSourceViewer.resetVisibleRegion(); - else - fSourceViewer.removeRangeIndication(); - } - - /** - * Adjusts the highlight range so that at least the specified range - * is highlighted. <p> - * Subclasses may re-implement this method. - * - * @param offset the offset of the range which at least should be highlighted - * @param length the length of the range which at least should be highlighted - */ - protected void adjustHighlightRange(int offset, int length) { - if (fSourceViewer == null) - return; - - if (!fSourceViewer.overlapsWithVisibleRegion(offset, length)) - fSourceViewer.resetVisibleRegion(); - } - - /* - * @see ITextEditor#selectAndReveal - */ - public void selectAndReveal(int start, int length) { - if (fSourceViewer == null) - return; - - ISelection selection= getSelectionProvider().getSelection(); - if (selection instanceof TextSelection) { - TextSelection textSelection= (TextSelection) selection; - if (textSelection.getOffset() != 0 || textSelection.getLength() != 0) - markInNavigationHistory(); - } - - StyledText widget= fSourceViewer.getTextWidget(); - widget.setRedraw(false); - { - adjustHighlightRange(start, length); - - fSourceViewer.revealRange(start, length); - fSourceViewer.setSelectedRange(start, length); - - markInNavigationHistory(); - } - widget.setRedraw(true); - } - - /* - * @see org.eclipse.ui.INavigationLocationProvider#createNavigationLocation() - * 2.1 - WORK_IN_PROGRESS do not use. - */ - public INavigationLocation createLocation() { - return new TextSelectionNavigationLocation(this,false); - } - /* - * @see org.eclipse.ui.INavigationLocationProvider#createNavigationLocation() - * 2.1 - WORK_IN_PROGRESS do not use. - */ - public INavigationLocation createCurrentLocation() { - return new TextSelectionNavigationLocation(this,true); - } - /** - * Writes a check mark of the given situation into the navigation history. - * 2.1 - WORK_IN_PROGRESS do not use. - */ - protected void markInNavigationHistory() { - IWorkbenchPage page= getEditorSite().getPage(); - page.getNavigationHistory().markLocation(); - fUserCurrentLocation = null; - } - - /** - * Subclasses may extend. - * 2.1 - WORK_IN_PROGRESS do not use. - */ - protected void editorSaved() { - IWorkbenchPage page= getEditorSite().getPage(); - INavigationLocation[] locations= page.getNavigationHistory().getLocations(); - IEditorInput input = getEditorInput(); - for (int i= 0; i < locations.length; i++) { - if (locations[i] instanceof TextSelectionNavigationLocation) { - if(input.equals(locations[i].getInput())) { - TextSelectionNavigationLocation location= (TextSelectionNavigationLocation) locations[i]; - location.partSaved(this); - } - } - } - } - - /* - * @see EditorPart#firePropertyChange - */ - protected void firePropertyChange(int property) { - super.firePropertyChange(property); - updatePropertyDependentActions(); - } - - /* - * @see ITextEditorExtension#setStatusField(IStatusField, String) - * @since 2.0 - */ - public void setStatusField(IStatusField field, String category) { - Assert.isNotNull(category); - if (field != null) { - - if (fStatusFields == null) - fStatusFields= new HashMap(3); - - fStatusFields.put(category, field); - updateStatusField(category); - - } else if (fStatusFields != null) - fStatusFields.remove(category); - } - - /** - * Returns the current status field for the given status category. - * - * @param category the status category - * @return the current status field for the given status category. - * @since 2.0 - */ - protected IStatusField getStatusField(String category) { - if (category != null && fStatusFields != null) - return (IStatusField) fStatusFields.get(category); - return null; - } - - /** - * Returns whether this editor is in overwrite or insert mode. - * - * @return <code>true</code> if in insert mode, <code>false</code> for overwrite mode - * @since 2.0 - */ - protected boolean isInInsertMode() { - return !fOverwriting; - } - - /** - * Handles a potential change of the cursor position. Subclasses may extend. - * @since 2.0 - */ - protected void handleCursorPositionChanged() { - updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION); - INavigationHistory history = getSite().getPage().getNavigationHistory(); - if(fUserCurrentLocation == null) { - INavigationLocation location = history.getCurrentLocation(); - markInNavigationHistory(); - INavigationLocation newLocation = history.getCurrentLocation(); - if(newLocation != location) - fUserCurrentLocation = newLocation; - } - } - - /** - * Handles a change of the editor's insert mode. Subclasses may extend. - * @since 2.0 - */ - protected void handleInsertModeChanged() { - updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE); - } - - /** - * Updates the status fields for the given category. - * @param category - * @since 2.0 - */ - protected void updateStatusField(String category) { - - if (category == null) - return; - - IStatusField field= getStatusField(category); - if (field != null) { - - String text= null; - - if (ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION.equals(category)) - text= getCursorPosition(); - else if (ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE.equals(category)) - text= isEditorInputReadOnly() ? fReadOnlyLabel : fWritableLabel; - else if (ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE.equals(category)) - text= isInInsertMode() ? fInsertModeLabel : fOverwriteModeLabel; - - field.setText(text == null ? fErrorLabel : text); - } - } - - /** - * Updates all status fields. - * @since 2.0 - */ - protected void updateStatusFields() { - if (fStatusFields != null) { - Iterator e= fStatusFields.keySet().iterator(); - while (e.hasNext()) - updateStatusField((String) e.next()); - } - } - - /** - * Returns a description of the cursor position. - * @return a description of the cursor position - * @since 2.0 - */ - protected String getCursorPosition() { - - if (fSourceViewer == null) - return fErrorLabel; - - StyledText styledText= fSourceViewer.getTextWidget(); - - int offset= fSourceViewer.getVisibleRegion().getOffset(); - int caret= offset + styledText.getCaretOffset(); - IDocument document= fSourceViewer.getDocument(); - - if (document == null) - return fErrorLabel; - - try { - - int line= document.getLineOfOffset(caret); - - int lineOffset= document.getLineOffset(line); - int tabWidth= styledText.getTabs(); - int column= 0; - for (int i= lineOffset; i < caret; i++) - if ('\t' == document.getChar(i)) - column += tabWidth - (column % tabWidth); - else - column++; - - fLineLabel.fValue= line + 1; - fColumnLabel.fValue= column + 1; - return MessageFormat.format(fPositionLabelPattern, fPositionLabelPatternArguments); - - } catch (BadLocationException x) { - return fErrorLabel; - } - } - - /* - * @see ITextEditorExtension#isEditorInputReadOnly() - * @since 2.0 - */ - public boolean isEditorInputReadOnly() { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - return extension.isReadOnly(getEditorInput()); - } - return true; - } - - /* - * @see ITextEditorExtension#addRulerContextMenuListener(IMenuListener) - * @since 2.0 - */ - public void addRulerContextMenuListener(IMenuListener listener) { - fRulerContextMenuListeners.add(listener); - } - - /* - * @see ITextEditorExtension#removeRulerContextMenuListener(IMenuListener) - * @since 2.0 - */ - public void removeRulerContextMenuListener(IMenuListener listener) { - fRulerContextMenuListeners.remove(listener); - } - - /** - * Returns wether this editor can handle the move of the original element - * so that it ends up being the moved element. By default this method returns - * <code>true</code>. Subclasses may reimplement. - * @param originalElement the original element - * @param movedElement the moved element - * @since 2.0 - */ - protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) { - return true; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AddMarkerAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AddMarkerAction.java deleted file mode 100644 index b01473659df..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AddMarkerAction.java +++ /dev/null @@ -1,279 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IInputValidator; -import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI; - - - -/** - * Action for creating a marker of a specified type for the editor's - * input element based on the editor's selection. If required, the - * action asks the user to provide a marker label. The action is initially - * associated with a text editor via the constructor, but that can be - * subsequently changed using <code>setEditor</code>. - * <p> - * The following keys, prepended by the given option prefix, - * are used for retrieving resources from the given bundle: - * <ul> - * <li><code>"dialog.title"</code> - the input dialog's title</li> - * <li><code>"dialog.message"</code> - the input dialog's message</li> - * <li><code>"error.dialog.title"</code> - the error dialog's title</li> - * <li><code>"error.dialog.message"</code> - the error dialog's message</li> - * </ul> - * This class may be instantiated but is not intended for subclassing. - * </p> - */ -public class AddMarkerAction extends TextEditorAction { - - - /** The type for newly created markers */ - private String fMarkerType; - /** Should the user be asked for a label? */ - private boolean fAskForLabel; - /** The action's resource bundle */ - private ResourceBundle fBundle; - /** The prefix used for resource bundle lookup */ - private String fPrefix; - - - /** - * Creates a new action for the given text editor. The action configures its - * visual representation from the given resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @param markerType the type of marker to add - * @param askForLabel <code>true</code> if the user should be asked for - * a label for the new marker - * @see ResourceAction#ResourceAction - */ - public AddMarkerAction(ResourceBundle bundle, String prefix, ITextEditor textEditor, String markerType, boolean askForLabel) { - super(bundle, prefix, textEditor); - fBundle= bundle; - fPrefix= prefix; - fMarkerType= markerType; - fAskForLabel= askForLabel; - } - - /** - * Returns this action's resource bundle. - * - * @return this action's resource bundle - */ - protected ResourceBundle getResourceBundle() { - return fBundle; - } - - /** - * Returns this action's resource key prefix. - * - * @return this action's resource key prefix - */ - protected String getResourceKeyPrefix() { - return fPrefix; - } - - /* - * @see IAction#run() - */ - public void run() { - IResource resource= getResource(); - if (resource == null) - return; - Map attributes= getInitialAttributes(); - if (fAskForLabel) { - if (!askForLabel(attributes)) - return; - } - - try { - MarkerUtilities.createMarker(resource, attributes, fMarkerType); - } catch (CoreException x) { - - Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog().log(x.getStatus()); - - Shell shell= getTextEditor().getSite().getShell(); - String title= getString(fBundle, fPrefix + "error.dialog.title", fPrefix + "error.dialog.title"); //$NON-NLS-2$ //$NON-NLS-1$ - String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$ - - ErrorDialog.openError(shell, title, msg, x.getStatus()); - } - } - - /* - * @see TextEditorAction#update() - */ - public void update() { - setEnabled(getResource() != null); - } - - /** - * Asks the user for a marker label. Returns <code>true</code> if a label - * is entered, <code>false</code> if the user cancels the input dialog. - * The value for the attribute <code>message</code> is modified in the given - * attribute map. - * - * @param attributes the attributes map - * @return <code>true</code> if a label has been entered - */ - protected boolean askForLabel(Map attributes) { - - Object o= attributes.get("message"); //$NON-NLS-1$ - String proposal= (o instanceof String) ? (String) o : ""; //$NON-NLS-1$ - if (proposal == null) - proposal= ""; //$NON-NLS-1$ - - String title= getString(fBundle, fPrefix + "dialog.title", fPrefix + "dialog.title"); //$NON-NLS-2$ //$NON-NLS-1$ - String message= getString(fBundle, fPrefix + "dialog.message", fPrefix + "dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$ - IInputValidator inputValidator = new IInputValidator() { - public String isValid(String newText) { - return (newText == null || newText.length() == 0) ? " " : null; //$NON-NLS-1$ - } - }; - InputDialog dialog= new InputDialog(getTextEditor().getSite().getShell(), title, message, proposal, inputValidator); - - String label= null; - if (dialog.open() != Window.CANCEL) - label= dialog.getValue(); - - if (label == null) - return false; - - label= label.trim(); - if (label.length() == 0) - return false; - - attributes.put("message", label); //$NON-NLS-1$ - return true; - } - - /** - * Returns the attributes the new marker will be initialized with. - * Subclasses may extend or replace this method. - * - * @return the attributes the new marker will be initialized with - */ - protected Map getInitialAttributes() { - - Map attributes= new HashMap(11); - - ITextSelection selection= (ITextSelection) getTextEditor().getSelectionProvider().getSelection(); - if (!selection.isEmpty()) { - - int start= selection.getOffset(); - int length= selection.getLength(); - - if (length < 0) { - length= -length; - start -= length; - } - - MarkerUtilities.setCharStart(attributes, start); - MarkerUtilities.setCharEnd(attributes, start + length); - - // marker line numbers are 1-based - int line= selection.getStartLine(); - MarkerUtilities.setLineNumber(attributes, line == -1 ? -1 : line + 1); - - IDocument document= getTextEditor().getDocumentProvider().getDocument(getTextEditor().getEditorInput()); - MarkerUtilities.setMessage(attributes, getLabelProposal(document, start, length)); - - } - - return attributes; - } - - /** - * Returns the initial label for the marker. - * - * @param document the document from which to extract a label proposal - * @param offset the document offset of the range from which to extract the label proposal - * @param length the length of the range from which to extract the label proposal - * @return the label proposal - */ - protected String getLabelProposal(IDocument document, int offset, int length) { - - - try { - - - if (length > 0) - return document.get(offset, length); - - - char ch; - - // Get the first white char before the selection. - int left= offset; - - int line= document.getLineOfOffset(offset); - int limit= document.getLineOffset(line); - - while (left > limit) { - ch= document.getChar(left); - if (Character.isWhitespace(ch)) - break; - --left; - } - - limit += document.getLineLength(line); - - // Now get the first letter. - while (left <= limit) { - ch= document.getChar(left); - if (!Character.isWhitespace(ch)) - break; - ++left; - } - - if (left > limit) - return null; - - // Get the next white char. - int right= (offset + length > limit ? limit : offset + length); - while (right < limit) { - ch= document.getChar(right); - if (Character.isWhitespace(ch)) - break; - ++right; - } - - // Trim the string and return it. - if (left != right) { - String label= document.get(left, right - left); - return label.trim(); - } - - } catch (BadLocationException x) { - // don't proposal label then - } - - return null; - } - - /** - * Returns the resource on which to create the marker, - * or <code>null</code> if there is no applicable resource. This - * queries the editor's input using <code>getAdapter(IResource.class)</code>. - * Subclasses may override this method. - * - * @return the resource to which to attach the newly created marker - */ - protected IResource getResource() { - ITextEditor editor= getTextEditor(); - if (editor != null) { - IEditorInput input= editor.getEditorInput(); - return (IResource) ((IAdaptable) input).getAdapter(IResource.class); - } - return null; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicMarkerUpdater.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicMarkerUpdater.java deleted file mode 100644 index a21e707f4df..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicMarkerUpdater.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - -import org.eclipse.core.resources.IMarker; - - -/** - * Updates a marker's positional attributes which are - * start position, end position, and line number. - */ -public final class BasicMarkerUpdater implements IMarkerUpdater { - - private final static String[] ATTRIBUTES= { - IMarker.CHAR_START, - IMarker.CHAR_END, - IMarker.LINE_NUMBER - }; - - /** - * Creates a new basic marker updater. - */ - public BasicMarkerUpdater() { - super(); - } - - /* - * @see IMarkerUpdater#getAttribute() - */ - public String[] getAttribute() { - return ATTRIBUTES; - } - - /* - * @see IMarkerUpdater#getMarkerType() - */ - public String getMarkerType() { - return null; - } - - /* - * @see IMarkerUpdater#updateMarker(IMarker, IDocument, Position) - */ - public boolean updateMarker(IMarker marker, IDocument document, Position position) { - - if (position == null) - return true; - - if (position.isDeleted()) - return false; - - boolean offsetsInitialized= false; - boolean offsetsChanged= false; - int markerStart= MarkerUtilities.getCharStart(marker); - int markerEnd= MarkerUtilities.getCharEnd(marker); - - if (markerStart != -1 && markerEnd != -1) { - - offsetsInitialized= true; - - int offset= position.getOffset(); - if (markerStart != offset) { - MarkerUtilities.setCharStart(marker, offset); - offsetsChanged= true; - } - - offset += position.getLength(); - if (markerEnd != offset) { - MarkerUtilities.setCharEnd(marker, offset); - offsetsChanged= true; - } - } - - if (!offsetsInitialized || (offsetsChanged && MarkerUtilities.getLineNumber(marker) != -1)) { - try { - // marker line numbers are 1-based - MarkerUtilities.setLineNumber(marker, document.getLineOfOffset(position.getOffset()) + 1); - } catch (BadLocationException x) { - } - } - - return true; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java deleted file mode 100644 index d4a62e84c78..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BasicTextEditorActionContributor.java +++ /dev/null @@ -1,228 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.action.IMenuManager; - -import org.eclipse.jface.action.IStatusLineManager; - -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.part.EditorActionBarContributor; - - - -/** - * Manages the installation and deinstallation of global actions for - * the same type of editors. - * <p> - * If instantiated and used as-is, this contributor connects to all of the workbench defined - * global editor actions the corresponding actions of the current editor. It also adds addition - * actions for searching and navigation (go to line) as well as a set of status fields. - * <p> - * Subclasses may override the following methods: - * <ul> - * <li><code>contributeToMenu</code> - extend to contribute to menu</li> - * <li><code>contributeToToolBar</code> - reimplement to contribute to toolbar</li> - * <li><code>contributeToStatusLine</code> - reimplement to contribute to status line</li> - * <li><code>setActiveEditor</code> - extend to react to editor changes</li> - * </ul> - * </p> - * #see ITextEditorActionConstants - */ -public class BasicTextEditorActionContributor extends EditorActionBarContributor { - - /** The global actions to be connected with editor actions */ - private final static String[] ACTIONS= { - ITextEditorActionConstants.UNDO, - ITextEditorActionConstants.REDO, - ITextEditorActionConstants.CUT, - ITextEditorActionConstants.COPY, - ITextEditorActionConstants.PASTE, - ITextEditorActionConstants.DELETE, - ITextEditorActionConstants.SELECT_ALL, - ITextEditorActionConstants.FIND, - ITextEditorActionConstants.BOOKMARK, - ITextEditorActionConstants.ADD_TASK, - ITextEditorActionConstants.PRINT, - ITextEditorActionConstants.REVERT - }; - - /** - * The status fields to be set to the editor - * @since 2.0 - */ - private final static String[] STATUSFIELDS= { - ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE, - ITextEditorActionConstants.STATUS_CATEGORY_INPUT_MODE, - ITextEditorActionConstants.STATUS_CATEGORY_INPUT_POSITION - }; - - /** The active editor part */ - private IEditorPart fActiveEditorPart; - /** - * The find next action - * @since 2.0 - */ - private RetargetTextEditorAction fFindNext; - /** - * The find previous action - * @since 2.0 - */ - private RetargetTextEditorAction fFindPrevious; - /** - * The incremental find action - * @since 2.0 - */ - private RetargetTextEditorAction fIncrementalFind; - /** - * The reverse incremental find action - * @since 2.1 - */ - private RetargetTextEditorAction fIncrementalFindReverse; - /** The go to line action */ - private RetargetTextEditorAction fGotoLine; - /** - * The map of status fields - * @since 2.0 - */ - private Map fStatusFields; - - - /** - * Creates an empty editor action bar contributor. The action bars are - * furnished later via the <code>init</code> method. - * - * @see org.eclipse.ui.IEditorActionBarContributor#init - */ - public BasicTextEditorActionContributor() { - - fFindNext= new RetargetTextEditorAction(EditorMessages.getResourceBundle(), "Editor.FindNext."); //$NON-NLS-1$ - fFindPrevious= new RetargetTextEditorAction(EditorMessages.getResourceBundle(), "Editor.FindPrevious."); //$NON-NLS-1$ - fIncrementalFind= new RetargetTextEditorAction(EditorMessages.getResourceBundle(), "Editor.FindIncremental."); //$NON-NLS-1$ - fIncrementalFindReverse= new RetargetTextEditorAction(EditorMessages.getResourceBundle(), "Editor.FindIncrementalReverse."); //$NON-NLS-1$ - fGotoLine= new RetargetTextEditorAction(EditorMessages.getResourceBundle(), "Editor.GotoLine."); //$NON-NLS-1$ - - fStatusFields= new HashMap(3); - for (int i= 0; i < STATUSFIELDS.length; i++) - fStatusFields.put(STATUSFIELDS[i], new StatusLineContributionItem(STATUSFIELDS[i])); - } - - /** - * Returns the active editor part. - * - * @return the active editor part - */ - protected final IEditorPart getActiveEditorPart() { - return fActiveEditorPart; - } - - /** - * Returns the action registered with the given text editor. - * - * @param editor the editor, or <code>null</code> - * @param actionId the action id - * @return the action, or <code>null</code> if none - */ - protected final IAction getAction(ITextEditor editor, String actionId) { - return (editor == null ? null : editor.getAction(actionId)); - } - - /** - * The method installs the global action handlers for the given text editor. - * This method cannot be overridden by subclasses. - * @since 2.0 - */ - private void doSetActiveEditor(IEditorPart part) { - - if (fActiveEditorPart == part) - return; - - if (fActiveEditorPart instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) fActiveEditorPart; - for (int i= 0; i < STATUSFIELDS.length; i++) - extension.setStatusField(null, STATUSFIELDS[i]); - } - - fActiveEditorPart= part; - ITextEditor editor= (part instanceof ITextEditor) ? (ITextEditor) part : null; - - IActionBars actionBars= getActionBars(); - if (actionBars != null) { - for (int i= 0; i < ACTIONS.length; i++) - actionBars.setGlobalActionHandler(ACTIONS[i], getAction(editor, ACTIONS[i])); - } - - fFindNext.setAction(getAction(editor, ITextEditorActionConstants.FIND_NEXT)); - fFindPrevious.setAction(getAction(editor, ITextEditorActionConstants.FIND_PREVIOUS)); - fIncrementalFind.setAction(getAction(editor, ITextEditorActionConstants.FIND_INCREMENTAL)); - fIncrementalFindReverse.setAction(getAction(editor, ITextEditorActionConstants.FIND_INCREMENTAL_REVERSE)); - fGotoLine.setAction(getAction(editor, ITextEditorActionConstants.GOTO_LINE)); - - if (fActiveEditorPart instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) fActiveEditorPart; - for (int i= 0; i < STATUSFIELDS.length; i++) - extension.setStatusField((IStatusField) fStatusFields.get(STATUSFIELDS[i]), STATUSFIELDS[i]); - } - } - - /** - * The <code>BasicTextEditorActionContributor</code> implementation of this - * <code>IEditorActionBarContributor</code> method installs the global - * action handler for the given text editor by calling a private helper - * method. Subclasses may extend. - */ - public void setActiveEditor(IEditorPart part) { - doSetActiveEditor(part); - } - - /* - * @see EditorActionBarContributor#contributeToMenu(IMenuManager) - */ - public void contributeToMenu(IMenuManager menu) { - - IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); - if (editMenu != null) { - editMenu.appendToGroup(IWorkbenchActionConstants.FIND_EXT, fFindNext); - editMenu.appendToGroup(IWorkbenchActionConstants.FIND_EXT,fFindPrevious); - editMenu.appendToGroup(IWorkbenchActionConstants.FIND_EXT,fIncrementalFind); - editMenu.appendToGroup(IWorkbenchActionConstants.FIND_EXT,fIncrementalFindReverse); - editMenu.appendToGroup(IWorkbenchActionConstants.FIND_EXT,fGotoLine); - } - } - - /* - * @see EditorActionBarContributor#contributeToStatusLine(IStatusLineManager) - * @since 2.0 - */ - public void contributeToStatusLine(IStatusLineManager statusLineManager) { - super.contributeToStatusLine(statusLineManager); - for (int i= 0; i < STATUSFIELDS.length; i++) - statusLineManager.add((IContributionItem) fStatusFields.get(STATUSFIELDS[i])); - } - - /* - * @see IEditorActionBarContributor#dispose() - * @since 2.0 - */ - public void dispose() { - doSetActiveEditor(null); - super.dispose(); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BookmarkRulerAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BookmarkRulerAction.java deleted file mode 100644 index 4444508b1b5..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/BookmarkRulerAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v0.5 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v05.html - -Contributors: - IBM Corporation - Initial implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.core.resources.IMarker; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.source.IVerticalRulerInfo; - -/** - * Adapter for the managing bookmark action. - * @since 2.0 - */ -public class BookmarkRulerAction extends AbstractRulerActionDelegate { - - /* - * @see AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo) - */ - protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { - return new MarkerRulerAction(EditorMessages.getResourceBundle(), "Editor.ManageBookmarks.", editor, rulerInfo, IMarker.BOOKMARK, true); //$NON-NLS-1$ - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ContentAssistAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ContentAssistAction.java deleted file mode 100644 index b8d4e21017a..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ContentAssistAction.java +++ /dev/null @@ -1,126 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.ITextOperationTargetExtension; -import org.eclipse.jface.text.source.ISourceViewer; - -import org.eclipse.ui.IWorkbenchPartSite; - - -/** - * A content asisst action which gets its target from its text editor. - * <p> - * The action is initially associated with a text editor via the constructor, - * but can subsequently be changed using <code>setEditor</code>. - * </p> - * <p> - * If this class is used as is, it works by asking the text editor for its text operation target - * (using <code>getAdapter(ITextOperationTarget.class)</code> and runs the content assist - * operation on this target. - * </p> - * @since 2.0 - */ -public final class ContentAssistAction extends TextEditorAction { - - /** The text operation target */ - private ITextOperationTarget fOperationTarget; - - /** - * Creates and initializes the action for the given text editor. - * The action configures its visual representation from the given resource - * bundle. The action works by asking the text editor at the time for its - * text operation target adapter (using - * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs the - * content assist operation on this target. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @see ResourceAction#ResourceAction - */ - public ContentAssistAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - update(); - } - - /** - * Runs the content assist operation on the editor's text operation target. - */ - public void run() { - if (fOperationTarget != null) { - - ITextEditor editor= getTextEditor(); - if (editor != null) { - - Display display= null; - - IWorkbenchPartSite site= editor.getSite(); - Shell shell= site.getShell(); - if (shell != null && !shell.isDisposed()) - display= shell.getDisplay(); - - BusyIndicator.showWhile(display, new Runnable() { - public void run() { - fOperationTarget.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS); - } - }); - } - } - } - - /** - * The <code>ContentAssistAction</code> implementation of this - * <code>IUpdate</code> method discovers the operation through the current - * editor's <code>ITextOperationTarget</code> adapter, and sets the - * enabled state accordingly. - */ - public void update() { - - ITextEditor editor= getTextEditor(); - - if (fOperationTarget == null && editor!= null) - fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); - - if (fOperationTarget == null) { - setEnabled(false); - return; - } - - if (editor instanceof ITextEditorExtension && fOperationTarget instanceof ITextOperationTargetExtension) { - ITextEditorExtension extension= (ITextEditorExtension) editor; - ITextOperationTargetExtension targetExtension= (ITextOperationTargetExtension) fOperationTarget; - boolean isEnabled= !extension.isEditorInputReadOnly(); - targetExtension.enableOperation(ISourceViewer.CONTENTASSIST_PROPOSALS, isEnabled); - } - - setEnabled(fOperationTarget.canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)); - } - - /* - * @see TextEditorAction#setEditor(ITextEditor) - */ - public void setEditor(ITextEditor editor) { - super.setEditor(editor); - fOperationTarget= null; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConvertLineDelimitersAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConvertLineDelimitersAction.java deleted file mode 100644 index 7c41f48f66c..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConvertLineDelimitersAction.java +++ /dev/null @@ -1,286 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.lang.reflect.InvocationTargetException; -import java.util.ResourceBundle; - -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.runtime.IProgressMonitor; - -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.IRewriteTarget; - - -/** - * An action to convert line delimiters of a text editor document to a particular line - * delimiter. - * @since 2.0 - */ -public class ConvertLineDelimitersAction extends TextEditorAction { - - /** The target line delimiter. */ - private final String fLineDelimiter; - - /** - * Creates a line delimiter conversion action. - * - * @param editor the editor - * @param lineDelimiter the target line delimiter to convert the editor's document to - */ - public ConvertLineDelimitersAction(ITextEditor editor, String lineDelimiter) { - this(EditorMessages.getResourceBundle(), "dummy", editor, lineDelimiter); //$NON-NLS-1$ - } - - /** - * Creates a line delimiter conversion action. - * - * @param bundle the resource bundle - * @param prefix the prefix for the resource bundle lookup - * @param editor the editor - * @param lineDelimiter the target line delimiter to convert the editor's document to - */ - public ConvertLineDelimitersAction(ResourceBundle bundle, String prefix, ITextEditor editor, String lineDelimiter) { - super(bundle, prefix, editor); - fLineDelimiter= lineDelimiter; - - String platformLineDelimiter= System.getProperty("line.separator"); //$NON-NLS-1$ - setText(EditorMessages.getString(getLabelKey(fLineDelimiter, platformLineDelimiter))); - - update(); - } - - /* - * @see Action#run() - */ - public void run() { - - try { - - ITextEditor editor= getTextEditor(); - if (editor == null) - return; - - Object adapter= editor.getAdapter(IRewriteTarget.class); - if (adapter instanceof IRewriteTarget) { - - IRewriteTarget target= (IRewriteTarget) adapter; - IDocument document= target.getDocument(); - if (document != null) { - Shell shell= getTextEditor().getSite().getShell(); - ConvertRunnable runnable= new ConvertRunnable(target, fLineDelimiter); - - if (document.getNumberOfLines() < 40) { - BusyIndicator.showWhile(shell.getDisplay(), runnable); - - } else { - ProgressMonitorDialog dialog= new ProgressMonitorDialog(shell); - dialog.run(false, true, runnable); - } - } - } - - } catch (InterruptedException e) { - // action cancelled - - } catch (InvocationTargetException e) { - // should not happen - } - } - - /** - * Converts all line delimiters of the document to <code>lineDelimiter</code>. - */ - private static class ConvertRunnable implements IRunnableWithProgress, Runnable { - - private final IRewriteTarget fRewriteTarget; - private final String fLineDelimiter; - - public ConvertRunnable(IRewriteTarget rewriteTarget, String lineDelimiter) { - fRewriteTarget= rewriteTarget; - fLineDelimiter= lineDelimiter; - } - - private static class DummyMonitor implements IProgressMonitor { - public void beginTask(String name, int totalWork) {} - public void done() {} - public void internalWorked(double work) {} - public boolean isCanceled() {return false;} - public void setCanceled(boolean value) {} - public void setTaskName(String name) {} - public void subTask(String name) {} - public void worked(int work) {} - } - - /* - * @see IRunnableWithProgress#run(IProgressMonitor) - */ - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - - IDocument document= fRewriteTarget.getDocument(); - final int lineCount= document.getNumberOfLines(); - monitor.beginTask(EditorMessages.getString("Editor.ConvertLineDelimiter.title"), lineCount); //$NON-NLS-1$ - - fRewriteTarget.setRedraw(false); - fRewriteTarget.beginCompoundChange(); - - if (document instanceof IDocumentExtension) - ((IDocumentExtension) document).startSequentialRewrite(true); - - IDocumentPartitioner partitioner= document.getDocumentPartitioner(); - if (partitioner != null) { - partitioner.disconnect(); - document.setDocumentPartitioner(null); - } - - try { - for (int i= 0; i < lineCount; i++) { - if (monitor.isCanceled()) - throw new InterruptedException(); - - final String delimiter= document.getLineDelimiter(i); - if (delimiter != null && delimiter.length() > 0 && !delimiter.equals(fLineDelimiter)) { - IRegion region= document.getLineInformation(i); - document.replace(region.getOffset() + region.getLength(), delimiter.length(), fLineDelimiter); - } - - monitor.worked(1); - } - - } catch (BadLocationException e) { - throw new InvocationTargetException(e); - - } finally { - - if (partitioner != null) { - partitioner.connect(document); - document.setDocumentPartitioner(partitioner); - } - - if (document instanceof IDocumentExtension) - ((IDocumentExtension) document).stopSequentialRewrite(); - - fRewriteTarget.endCompoundChange(); - fRewriteTarget.setRedraw(true); - - monitor.done(); - } - } - - /* - * @see Runnable#run() - */ - public void run() { - try { - run(new DummyMonitor()); - - } catch (InterruptedException e) { - // cancelled, can't happen with dummy monitor - - } catch (InvocationTargetException e) { - // should not happen - } - } - } - - /** - * Returns whether the given document uses only the given line delimiter. - * @param document the document to check - * @param lineDelimiter the line delimiter to check for - */ - private static boolean usesLineDelimiterExclusively(IDocument document, String lineDelimiter) { - - try { - final int lineCount= document.getNumberOfLines(); - for (int i= 0; i < lineCount; i++) { - final String delimiter= document.getLineDelimiter(i); - if (delimiter != null && delimiter.length() > 0 && !delimiter.equals(lineDelimiter)) - return false; - } - - } catch (BadLocationException e) { - return false; - } - - return true; - } - - /** - * Computes and returns the key to be used to lookup the action's label in - * its resource bundle. - * - * @param lineDelimiter the line delimiter - * @param platformLineDelimiter the platform line delimiter - */ - private static String getLabelKey(String lineDelimiter, String platformLineDelimiter) { - if (lineDelimiter.equals(platformLineDelimiter)) { - - if (lineDelimiter.equals("\r\n")) //$NON-NLS-1$ - return "Editor.ConvertLineDelimiter.toWindows.default.label"; //$NON-NLS-1$ - - if (lineDelimiter.equals("\n")) //$NON-NLS-1$ - return "Editor.ConvertLineDelimiter.toUNIX.default.label"; //$NON-NLS-1$ - - if (lineDelimiter.equals("\r")) //$NON-NLS-1$ - return "Editor.ConvertLineDelimiter.toMac.default.label"; //$NON-NLS-1$ - - } else { - - if (lineDelimiter.equals("\r\n")) //$NON-NLS-1$ - return "Editor.ConvertLineDelimiter.toWindows.label"; //$NON-NLS-1$ - - if (lineDelimiter.equals("\n")) //$NON-NLS-1$ - return "Editor.ConvertLineDelimiter.toUNIX.label"; //$NON-NLS-1$ - - if (lineDelimiter.equals("\r")) //$NON-NLS-1$ - return "Editor.ConvertLineDelimiter.toMac.label"; //$NON-NLS-1$ - } - - return null; - } - - /** - * Internally sets the enable state of this action. - */ - private boolean doEnable() { - ITextEditor editor= getTextEditor(); - if (editor == null) - return false; - - if (editor instanceof ITextEditorExtension && ((ITextEditorExtension) editor).isEditorInputReadOnly()) - return false; - -// IDocument document= getDocument(); -// if (document == null || usesLineDelimiterExclusively(document, fLineDelimiter)) -// return false; - - return isEnabled(); - } - - /* - * @see IUpdate#update() - */ - public void update() { - super.update(); - setEnabled(doEnable()); - } - -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultRangeIndicator.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultRangeIndicator.java deleted file mode 100644 index 34762756478..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultRangeIndicator.java +++ /dev/null @@ -1,146 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -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.Control; -import org.eclipse.swt.widgets.Display; - - -/** - * Specialized annotation to indicate a particular range of text lines. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * This class is instantiated automatically by <code>AbstractTextEditor</code>. - * </p> - */ -public class DefaultRangeIndicator extends Annotation { - - private static PaletteData fgPaletteData; - private Image fImage; - - /** - * Creates a new range indicator. - */ - public DefaultRangeIndicator() { - super(); - setLayer(0); - } - - /* - * @see Annotation#paint - */ - public void paint(GC gc, Canvas canvas, Rectangle bounds) { - - Point canvasSize= canvas.getSize(); - - int x= 0; - int y= bounds.y; - int w= canvasSize.x; - int h= bounds.height; - int b= 1; - - if (y + h > canvasSize.y) - h= canvasSize.y - y; - - if (y < 0) { - h= h + y; - y= 0; - } - - if (h <= 0) - return; - - Image image = getImage(canvas); - gc.drawImage(image, 0, 0, w, h, x, y, w, h); - - gc.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)); - gc.fillRectangle(x, bounds.y, w, b); - gc.fillRectangle(x, bounds.y + bounds.height - b, w, b); - } - - private Image getImage(Control control) { - if (fImage == null) { - fImage= createImage(control.getDisplay(), control.getSize()); - - control.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - if (fImage != null && !fImage.isDisposed()) { - fImage.dispose(); - fImage= null; - } - } - }); - } else { - Rectangle imageRectangle= fImage.getBounds(); - Point controlSize= control.getSize(); - - if (imageRectangle.width < controlSize.x || imageRectangle.height < controlSize.y) { - fImage.dispose(); - fImage= createImage(control.getDisplay(), controlSize); - } - } - - return fImage; - } - - private static Image createImage(Display display, Point size) { - - int width= size.x; - int height= size.y; - - if (fgPaletteData == null) - fgPaletteData= createPalette(display); - - ImageData imageData= new ImageData(width, height, 1, fgPaletteData); - - for (int y= 0; y < height; y++) - for (int x= 0; x < width; x++) - imageData.setPixel(x, y, (x + y) % 2); - - return new Image(display, imageData); - } - - private static PaletteData createPalette(Display display) { - Color c1; - Color c2; - - if (false) { - // range lighter - c1= display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); - c2= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); - } else { - // range darker - c1= display.getSystemColor(SWT.COLOR_LIST_SELECTION); - c2= display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); - } - - RGB rgbs[]= new RGB[] { - new RGB(c1.getRed(), c1.getGreen(), c1.getBlue()), - new RGB(c2.getRed(), c2.getGreen(), c2.getBlue())}; - - return new PaletteData(rgbs); - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineAction.java deleted file mode 100644 index 17f17898787..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineAction.java +++ /dev/null @@ -1,145 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v0.5 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v05.html - -Contributors: - IBM Corporation - Initial implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; - -/** - * An action to delete a whole line, the fraction of the line that is left from the cursor - * or the fraction that is right from the cursor. - * @since 2.0 - */ -public class DeleteLineAction extends TextEditorAction { - - /** Delete the whole line. */ - public static final int WHOLE= 0; - /** Delete to the beginning of line. */ - public static final int TO_BEGINNING= 1; - /** Delete to the end of line. */ - public static final int TO_END= 2; - - /** The type of deletion */ - private final int fType; - /** The deletion target */ - private DeleteLineTarget fTarget; - - /** - * Creates a line delimiter conversion action. - * - * @param editor the editor - * @param type the line deletion type, must be one of - * <code>WHOLE_LINE</code>, <code>TO_BEGINNING</code> or <code>TO_END</code> - */ - public DeleteLineAction(ResourceBundle bundle, String prefix, ITextEditor editor, int type) { - super(bundle, prefix, editor); - fType= type; - update(); - } - - /** - * Returns the editor's document. - * - * @param editor the editor - * @return the editor's document - */ - private static IDocument getDocument(ITextEditor editor) { - - IDocumentProvider documentProvider= editor.getDocumentProvider(); - if (documentProvider == null) - return null; - - IDocument document= documentProvider.getDocument(editor.getEditorInput()); - if (document == null) - return null; - - return document; - } - - /** - * Returns the editor's selection. - * - * @param editor the editor - * @return the editor's selection - */ - private static ITextSelection getSelection(ITextEditor editor) { - - ISelectionProvider selectionProvider= editor.getSelectionProvider(); - if (selectionProvider == null) - return null; - - ISelection selection= selectionProvider.getSelection(); - if (!(selection instanceof ITextSelection)) - return null; - - return (ITextSelection) selection; - } - - /* - * @see IAction#run() - */ - public void run() { - - if (fTarget == null) - return; - - ITextEditor editor= getTextEditor(); - if (editor == null) - return; - - IDocument document= getDocument(editor); - if (document == null) - return; - - ITextSelection selection= getSelection(editor); - if (selection == null) - return; - - try { - fTarget.deleteLine(document, selection.getOffset(), fType); - } catch (BadLocationException e) { - // should not happen - } - } - - /* - * @see IUpdate#update() - */ - public void update() { - - super.update(); - if (!isEnabled()) - return; - - ITextEditor editor= getTextEditor(); - if (editor instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) editor; - if (extension.isEditorInputReadOnly()) { - setEnabled(false); - return; - } - } - - if (editor != null) - fTarget= (DeleteLineTarget) editor.getAdapter(DeleteLineTarget.class); - else - fTarget= null; - - setEnabled(fTarget != null); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineTarget.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineTarget.java deleted file mode 100644 index 7d139d99d64..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DeleteLineTarget.java +++ /dev/null @@ -1,278 +0,0 @@ -package org.eclipse.ui.texteditor; - -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; - -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.Region; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; - -/** - * A delete line target. - * @since 2.1 - */ -class DeleteLineTarget { - - /** - * A clipboard which concatenates subsequent delete line actions. - */ - private class DeleteLineClipboard implements MouseListener, ModifyListener, ISelectionChangedListener, ITextListener, FocusListener { - - /** The text viewer. */ - private final ITextViewer fViewer; - /* - * This is a hack to stop a string of deletions when the user moves - * the caret. This kludge is necessary since: - * 1) Moving the caret does not fire a selection event - * 2) There is no support in StyledText for a CaretListener - * 3) The AcceleratorScope and KeybindingService classes are internal - * - * This kludge works by comparing the offset of the caret to the offset - * recorded the last time the action was run. If they differ, we do not - * continue the session. - * - * @see #saveState - * @see #checkState - */ - /** The last known offset of the caret */ - private int fIndex= -1; - /** The clip board. */ - private Clipboard fClipboard; - /** A string buffer. */ - private final StringBuffer fBuffer= new StringBuffer(); - /** The deleting flag. */ - private boolean fDeleting; - - /** - * Creates the text viewer. - */ - public DeleteLineClipboard(ITextViewer viewer) { - Assert.isNotNull(viewer); - fViewer= viewer; - } - - public ITextViewer getViewer() { - return fViewer; - } - - /** - * Saves the current state, to be compared later using - * <code>checkState</code>. - */ - private void saveState() { - fIndex= fViewer.getTextWidget().getCaretOffset(); - } - - /** - * Checks that the state has not changed since it was saved. - * - * @return returns <code>true</code> if the current state is the same as - * when it was last saved. - */ - private boolean hasSameState() { - return fIndex == fViewer.getTextWidget().getCaretOffset(); - } - - public void checkState() { - - if (fClipboard == null) { - StyledText text= fViewer.getTextWidget(); - if (text == null) - return; - - fViewer.getSelectionProvider().addSelectionChangedListener(this); - text.addFocusListener(this); - text.addMouseListener(this); - text.addModifyListener(this); - - fClipboard= new Clipboard(text.getDisplay()); - fBuffer.setLength(0); - - } else if (!hasSameState()) { - fBuffer.setLength(0); - } - } - - public void append(String deltaString) { - fBuffer.append(deltaString); - String string= fBuffer.toString(); - Transfer[] dataTypes= new Transfer[] { TextTransfer.getInstance() }; - Object[] data= new Object[] { string }; - fClipboard.setContents(data, dataTypes); - } - - /** - * Uninstalls this action. - */ - private void uninstall() { - - if (fClipboard == null) - return; - - StyledText text= fViewer.getTextWidget(); - if (text == null) - return; - - fViewer.getSelectionProvider().removeSelectionChangedListener(this); - text.removeFocusListener(this); - text.removeMouseListener(this); - text.removeModifyListener(this); - - fClipboard.dispose(); - fClipboard= null; - } - - public void setDeleting(boolean deleting) { - fDeleting= deleting; - } - - /* - * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(MouseEvent) - */ - public void mouseDoubleClick(MouseEvent e) { - uninstall(); - } - - /* - * @see org.eclipse.swt.events.MouseListener#mouseDown(MouseEvent) - */ - public void mouseDown(MouseEvent e) { - uninstall(); - } - - /* - * @see org.eclipse.swt.events.MouseListener#mouseUp(MouseEvent) - */ - public void mouseUp(MouseEvent e) { - uninstall(); - } - - /* - * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - uninstall(); - } - - /* - * @see org.eclipse.swt.events.FocusListener#focusGained(FocusEvent) - */ - public void focusGained(FocusEvent e) { - uninstall(); - } - - /* - * @see org.eclipse.swt.events.FocusListener#focusLost(FocusEvent) - */ - public void focusLost(FocusEvent e) { - uninstall(); - } - - /* - * @see org.eclipse.jface.text.ITextListener#textChanged(TextEvent) - */ - public void textChanged(TextEvent event) { - uninstall(); - } - - /* - * @see org.eclipse.swt.events.ModifyListener#modifyText(ModifyEvent) - */ - public void modifyText(ModifyEvent e) { - if (!fDeleting) - uninstall(); - } - } - - /** The clipboard manager. */ - private final DeleteLineClipboard fClipboard; - - /** - * Constructor for DeleteLineTarget. - */ - public DeleteLineTarget(ITextViewer viewer) { - fClipboard= new DeleteLineClipboard(viewer); - } - - private static IRegion getDeleteRegion(IDocument document, int position, int type) throws BadLocationException { - - int line= document.getLineOfOffset(position); - int offset= 0; - int length= 0; - - switch (type) { - case DeleteLineAction.WHOLE: - offset= document.getLineOffset(line); - length= document.getLineLength(line); - break; - - case DeleteLineAction.TO_BEGINNING: - offset= document.getLineOffset(line); - length= position - offset; - break; - - case DeleteLineAction.TO_END: - offset= position; - - IRegion lineRegion= document.getLineInformation(line); - int end= lineRegion.getOffset() + lineRegion.getLength(); - - if (position == end) { - String lineDelimiter= document.getLineDelimiter(line); - length= lineDelimiter == null ? 0 : lineDelimiter.length(); - - } else { - length= end - offset; - } - break; - - default: - throw new IllegalArgumentException(); - } - - return new Region(offset, length); - } - - /** - * Deletes the specified fraction of the line of the given offset. - * - * @param document the document - * @param position the offset - * @param type the specification of what to delete - * @throws BadLocationException if position is not valid in the given document - */ - public void deleteLine(IDocument document, int position, int type) throws BadLocationException { - - IRegion deleteRegion= getDeleteRegion(document, position, type); - int offset= deleteRegion.getOffset(); - int length= deleteRegion.getLength(); - - if (length == 0) - return; - - fClipboard.checkState(); - fClipboard.append(document.get(offset, length)); - - fClipboard.setDeleting(true); - document.replace(offset, length, null); - fClipboard.setDeleting(false); - - fClipboard.saveState(); - } - -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java deleted file mode 100644 index 21cbe7418fb..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DocumentProviderRegistry.java +++ /dev/null @@ -1,287 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; - -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.PlatformUI; - - - - -/** - * This registry manages shareable document provider. Document - * providers are specified in <code>plugin.xml</code> either - * per name extension or per editor input type. A name extension - * rule always overrules an editor input type rule. Editor input - * type rules follow the same rules <code>IAdapterManager</code> - * used to find object adapters. - * - * @see org.eclipse.core.runtime.IAdapterManager - */ -public class DocumentProviderRegistry { - - /** The registry singleton. */ - private static DocumentProviderRegistry fgRegistry; - - /** - * Returns the standard document provider registry. - */ - public static DocumentProviderRegistry getDefault() { - if (fgRegistry == null) - fgRegistry= new DocumentProviderRegistry(); - return fgRegistry; - } - - - /** The mapping between name extensions and configuration elements. */ - private Map fExtensionMapping= new HashMap(); - /** The mapping between editor input type names and configuration elements. */ - private Map fInputTypeMapping= new HashMap(); - /** The mapping between configuration elements and instantiated document providers. */ - private Map fInstances= new HashMap(); - - - /** - * Creates a new document provider registry and intializes it with the information - * found in the plugin registry. - */ - private DocumentProviderRegistry() { - initialize(); - } - - /** - * Reads the comma-separated value of the given configuration element - * for the given attribute name and remembers the configuration element - * in the given map under the individual tokens of the attribute value. - */ - private void read(Map map, IConfigurationElement element, String attributeName) { - String value= element.getAttribute(attributeName); - if (value != null) { - StringTokenizer tokenizer= new StringTokenizer(value, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String token= tokenizer.nextToken().trim(); - - Set s= (Set) map.get(token); - if (s == null) { - s= new HashSet(); - map.put(token, s); - } - s.add(element); - } - } - } - - /** - * Initializes the document provider registry. It retrieves all implementers of the <code>documentProviders</code> - * extension point and remembers those implementers based on the name extensions and the editor input - * types they are for. - */ - private void initialize() { - - IExtensionPoint extensionPoint; - extensionPoint= Platform.getPluginRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, "documentProviders"); //$NON-NLS-1$ - - if (extensionPoint == null) { - String msg= MessageFormat.format(EditorMessages.getString("DocumentProviderRegistry.error.extension_point_not_found"), new Object[] { PlatformUI.PLUGIN_ID }); //$NON-NLS-1$ - ILog log= Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog(); - log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, msg, null)); - return; - } - - IConfigurationElement[] elements= extensionPoint.getConfigurationElements(); - for (int i= 0; i < elements.length; i++) { - read(fExtensionMapping, elements[i], "extensions"); //$NON-NLS-1$ - read(fInputTypeMapping, elements[i], "inputTypes"); //$NON-NLS-1$ - } - } - - /** - * Returns the document provider for the given configuration element. - * If there is no instantiated document provider remembered for this - * element, a new document provider is created and put into the cache. - */ - private IDocumentProvider getDocumentProvider(IConfigurationElement entry) { - IDocumentProvider provider= (IDocumentProvider) fInstances.get(entry); - if (provider == null) { - try { - provider= (IDocumentProvider) entry.createExecutableExtension("class"); //$NON-NLS-1$ - fInstances.put(entry, provider); - } catch (CoreException x) { - } - } - return provider; - } - - /** - * Returns the first enumerated element of the given set. - */ - private IConfigurationElement selectConfigurationElement(Set set) { - if (set != null && !set.isEmpty()) { - Iterator e= set.iterator(); - return (IConfigurationElement) e.next(); - } - return null; - } - - /** - * Returns a shareable document provider for the given name extension. - * - * @param extension the name extension to be used for lookup - * @return the shareable document provider - */ - public IDocumentProvider getDocumentProvider(String extension) { - - Set set= (Set) fExtensionMapping.get(extension); - if (set != null) { - IConfigurationElement entry= selectConfigurationElement(set); - return getDocumentProvider(entry); - } - return null; - } - - /** - * Computes the class hierarchy of the given type. The type is - * part of the computed hierarchy. - */ - private List computeClassList(Class type) { - - List result= new ArrayList(); - - Class c= type; - while (c != null) { - result.add(c); - c= c.getSuperclass(); - } - - return result; - } - - /** - * Computes the list of all interfaces for the given list of - * classes. The interface lists of the given classes are - * concatenated. - */ - private List computeInterfaceList(List classes) { - - List result= new ArrayList(4); - Hashtable visited= new Hashtable(4); - - Iterator e= classes.iterator(); - while (e.hasNext()) { - Class c= (Class) e.next(); - computeInterfaceList(c.getInterfaces(), result, visited); - } - - return result; - } - - /** - * Computes the list of all interfaces of the given list of interfaces, - * taking a depth-first approach. - */ - private void computeInterfaceList(Class[] interfaces, List result, Hashtable visited) { - - List toBeVisited= new ArrayList(interfaces.length); - - for (int i= 0; i < interfaces.length; i++) { - Class iface= interfaces[i]; - if (visited.get(iface) == null) { - visited.put(iface, iface); - result.add(iface); - toBeVisited.add(iface); - } - } - - Iterator e= toBeVisited.iterator(); - while(e.hasNext()) { - Class iface= (Class) e.next(); - computeInterfaceList(iface.getInterfaces(), result, visited); - } - } - - /** - * Returns the configuration elements for the first class in the list - * of given classes for which configuration elements have been remembered. - */ - private Object getFirstInputTypeMapping(List classes) { - Iterator e= classes.iterator(); - while (e.hasNext()) { - Class c= (Class) e.next(); - Object mapping= fInputTypeMapping.get(c.getName()); - if (mapping != null) - return mapping; - } - return null; - } - - /** - * Returns the appropriate configuration element for the given type. If - * there is no configuration element for the type's name, first the list of - * super classes is searched, and if not successful the list of all interfaces. - */ - private Object findInputTypeMapping(Class type) { - - if (type == null) - return null; - - Object mapping= fInputTypeMapping.get(type.getName()); - if (mapping != null) - return mapping; - - List classList= computeClassList(type); - mapping= getFirstInputTypeMapping(classList); - if (mapping != null) - return mapping; - - return getFirstInputTypeMapping(computeInterfaceList(classList)); - } - - /** - * Returns the shareable document for the type of the given editor input. - * - * @param editorInput the input for whose type the provider is looked up - * @return the shareable document provider - */ - public IDocumentProvider getDocumentProvider(IEditorInput editorInput) { - - IDocumentProvider provider= null; - - IFile file= (IFile) editorInput.getAdapter(IFile.class); - if (file != null) - provider= getDocumentProvider(file.getFileExtension()); - - if (provider == null) { - Set set= (Set) findInputTypeMapping(editorInput.getClass()); - if (set != null) { - IConfigurationElement entry= selectConfigurationElement(set); - provider= getDocumentProvider(entry); - } - } - - return provider; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.java deleted file mode 100644 index 6d672762a60..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.ui.texteditor; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -class EditorMessages { - - private static final String RESOURCE_BUNDLE= "org.eclipse.ui.texteditor.EditorMessages";//$NON-NLS-1$ - - private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); - - private EditorMessages() { - } - - public static String getString(String key) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ - } - } - - public static ResourceBundle getResourceBundle() { - return fgResourceBundle; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.properties b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.properties deleted file mode 100644 index 123617b0f7a..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorMessages.properties +++ /dev/null @@ -1,293 +0,0 @@ -############################################################# -# -# (c) Copyright IBM Corp. 2000, 2001. -# All Rights Reserved. -# -############################################################# - - -## Errors ## - -Editor.error.no_provider=Text editor does not have a document provider - -Editor.error.save.title=Save problems -Editor.error.save.message=Save could not be completed. - -Editor.error.save.deleted.title=Cannot Save -Editor.error.save.deleted.message=The file has been deleted. - - -Editor.error.save.outofsync.title=Update conflict -Editor.error.save.outofsync.message=The file has been changed on the file system. Do you want to overwrite the changes? - -Editor.error.activated.outofsync.title=File Changed -Editor.error.activated.outofsync.message=The file has been changed on the file system. Do you want to load the changes? - -Editor.error.activated.deleted.save.title=File Deleted -Editor.error.activated.deleted.save.message=The file has been deleted from the file system. Do you want to save your changes or close the editor without saving? -Editor.error.activated.deleted.save.button.save=Save -Editor.error.activated.deleted.save.button.close=Close -Editor.error.activated.deleted.close.title=File Deleted -Editor.error.activated.deleted.close.message=The file has been deleted from the file system. This editor will be closed. - -Editor.error.refresh.outofsync.title=Problems loading File -Editor.error.refresh.outofsync.message=The file could not be loaded from the file system. - -Editor.error.revert.title=Problems while reverting to saved state -Editor.error.revert.message=Could not revert to saved state. -Editor.error.setinput.title=Problem while opening -Editor.error.setinput.message=Cannot open input element: -Editor.error.no_input=Unable to read text editor input -Editor.error.invalid_input=Invalid text editor input - -AbstractDocumentProvider.error.save.inuse=File is either open in another editor or in use by an operation. - -DocumentProviderRegistry.error.extension_point_not_found=Extension point: {0}.documentProviders not found - - - -## Actions ## - -Editor.Undo.label=&Undo@Ctrl+Z -Editor.Undo.tooltip=Undo -Editor.Undo.image= -Editor.Undo.description=Undo - -Editor.Redo.label=&Redo@Ctrl+Y -Editor.Redo.tooltip=Redo -Editor.Redo.image= -Editor.Redo.description=Redo - -Editor.Cut.label=Cu&t@Ctrl+X -Editor.Cut.tooltip=Cut -Editor.Cut.image= -Editor.Cut.description=Cut - -Editor.Copy.label=&Copy@Ctrl+C -Editor.Copy.tooltip=Copy -Editor.Copy.image= -Editor.Copy.description=Copy - -Editor.Paste.label=&Paste@Ctrl+V -Editor.Paste.tooltip=Paste -Editor.Paste.image= -Editor.Paste.description=Paste - -Editor.Delete.label=&Delete@Delete -Editor.Delete.tooltip=Delete -Editor.Delete.image= -Editor.Delete.description=Delete - -Editor.Print.label=&Print@Ctrl+P -Editor.Print.tooltip=Print -Editor.Print.image= -Editor.Print.description=Print - -Editor.SelectAll.label=Select &All@Ctrl+A -Editor.SelectAll.tooltip=Select All -Editor.SelectAll.image= -Editor.SelectAll.description=Select All - -Editor.ShiftRight.label=Sh&ift Right -Editor.ShiftRight.tooltip=Shift Right -Editor.ShiftRight.image= -Editor.ShiftRight.description=Shift Right - -Editor.ShiftLeft.label=S&hift Left -Editor.ShiftLeft.tooltip=Shift Left -Editor.ShiftLeft.image= -Editor.ShiftLeft.description=Shift Left - -Editor.delete.line.submenu.label=D&elete Line - -Editor.DeleteLine.label=&Whole -Editor.DeleteLine.tooltip=Delete Line -Editor.DeleteLine= -Editor.DeleteLine.description=Delete Line - -Editor.DeleteLineToBeginning.label=To &Beginning -Editor.DeleteLineToBeginning.tooltip=Delete Line to Beginning -Editor.DeleteLineToBeginning= -Editor.DeleteLineToBeginning.description=Delete Line to Beginning - -Editor.DeleteLineToEnd.label=To &End -Editor.DeleteLineToEnd.tooltip=Delete Line to End -Editor.DeleteLineToEnd= -Editor.DeleteLineToEnd.description=Delete Line to End - -Editor.mark.status.message.mark.set=Mark set -Editor.mark.status.message.mark.cleared=Mark cleared -Editor.mark.status.message.mark.swapped=Mark swapped -Editor.mark.status.error.message.mark.not.set=Mark not set -Editor.mark.status.error.message.mark.not.visible=Mark not in visible region - -Editor.mark.submenu.label=&Mark - -Editor.SetMark.label=&Set -Editor.SetMark.tooltip=Set Mark -Editor.SetMark= -Editor.SetMark.description=Set Mark - -Editor.ClearMark.label=&Clear -Editor.ClearMark.tooltip=Clear Mark -Editor.ClearMark= -Editor.ClearMark.description=Clear Mark - -Editor.SwapMark.label=S&wap -Editor.SwapMark.tooltip=Swap Mark -Editor.SwapMark= -Editor.SwapMark.description=Swap Mark - -Editor.FindReplace.label=&Find/Replace...@Ctrl+F -Editor.FindReplace.tooltip=Find/Replace -Editor.FindReplace.image= -Editor.FindReplace.description=Find/Replace - -Editor.FindNext.label=Find &Next@Ctrl+K -Editor.FindNext.tooltip=Find Next -Editor.FindNext.image= -Editor.FindNext.description=Find Next - -Editor.FindPrevious.label=Find Pre&vious@Ctrl+Shift+K -Editor.FindPrevious.tooltip=Find Previous -Editor.FindPrevious.image= -Editor.FindPrevious.description=Find Previous - -Editor.FindIncremental.label=&Incremental Find Next@Ctrl+J -Editor.FindIncremental.tooltip=Incremental Find Next -Editor.FindIncremental.image= -Editor.FindIncremental.description=Incremental Find Next -Editor.FindIncremental.not_found.pattern={0}{1}Incremental Find: {2} not found -Editor.FindIncremental.found.pattern={0}{1}Incremental Find: {2} -Editor.FindIncremental.render.tab=<TAB> -# The following two properties must end in a space -Editor.FindIncremental.wrapped=Wrapped -Editor.FindIncremental.reverse=Reverse - -Editor.FindIncrementalReverse.label=Incre&mental Find Previous@Ctrl+Shift+J -Editor.FindIncrementalReverse.tooltip=Incremental Find Previous -Editor.FindIncrementalReverse.image= -Editor.FindIncrementalReverse.description=Incremental Find Previous - -Editor.AddBookmark.label=Boo&kmark... -Editor.AddBookmark.tooltip=Add Bookmark -Editor.AddBookmark.image= -Editor.AddBookmark.description=Add Bookmark -Editor.AddBookmark.dialog.title=Add Bookmark -Editor.AddBookmark.dialog.message=Enter Bookmark name -Editor.AddBookmark.error.dialog.title=Add Bookmark -Editor.AddBookmark.error.dialog.message=Problems adding new bookmark - -Editor.AddTask.label=&Task... -Editor.AddTask.tooltip=Add Task -Editor.AddTask.image= -Editor.AddTask.description=Add Task -Editor.AddTask.dialog.title=Add Task -Editor.AddTask.dialog.message=Enter Task description -Editor.AddTask.error.dialog.title=Add Task -Editor.AddTask.error.dialog.message=Problems adding new task - -Editor.Save.label=&Save@Ctrl+S -Editor.Save.tooltip=Save -Editor.Save.image= -Editor.Save.description=Save - -Editor.Revert.label=Re&vert -Editor.Revert.tooltip=Revert -Editor.Revert.image= -Editor.Revert.description=Revert - -Editor.GotoLine.label=&Go to Line...@Ctrl+L -Editor.GotoLine.tooltip=Go to Line -Editor.GotoLine.image= -Editor.GotoLine.description=Go to Line -Editor.GotoLine.dialog.title=Go to Line -Editor.GotoLine.dialog.message=Enter line number (1..{0}): -Editor.GotoLine.dialog.invalid_input=Not a number -Editor.GotoLine.dialog.invalid_range=Line number out of range - -Editor.ManageBookmarks.tooltip=Adds and Removes Bookmarks -Editor.ManageBookmarks.image= -Editor.ManageBookmarks.description=Adds and removes Bookmarks -Editor.ManageBookmarks.add.label=Add Boo&kmark... -Editor.ManageBookmarks.remove.label=Remove Boo&kmark -Editor.ManageBookmarks.add.dialog.title=Add Bookmark -Editor.ManageBookmarks.add.dialog.message=Enter Bookmark name -Editor.ManageBookmarks.error.dialog.title=Managing Bookmarks -Editor.ManageBookmarks.error.dialog.message=Problems managing bookmarks - -Editor.ManageTasks.tooltip=Adds and Removes Tasks -Editor.ManageTasks.image= -Editor.ManageTasks.description=Adds and removes Tasks -Editor.ManageTasks.add.label=Add &Task... -Editor.ManageTasks.remove.label=Remove &Task -Editor.ManageTasks.add.dialog.title=Add Task -Editor.ManageTasks.add.dialog.message=Enter Task description -Editor.ManageTasks.error.dialog.title=Managing Tasks -Editor.ManageTasks.error.dialog.message=Problems managing tasks - -Editor.SelectMarker.tooltip=Selects the marker's range -Editor.SelectMarker.image= -Editor.SelectMarker.description=Selects the Marker's Range -Editor.SelectMarker.label=Select &Marker Range -Editor.SelectMarker.error.dialog.title=Selecting Marker Range -Editor.SelectMarker.error.dialog.message=Problems selecting marker range - -Editor.ConvertLineDelimiter.title=Converting line delimiters... -Editor.ConvertLineDelimiter.toWindows.label=to CRLF (&Windows) -Editor.ConvertLineDelimiter.toWindows.default.label=to CRLF (&Windows) [default] -Editor.ConvertLineDelimiter.toUNIX.label=to LF (&UNIX, MacOS X) -Editor.ConvertLineDelimiter.toUNIX.default.label=to LF (&UNIX, MacOS X) [default] -Editor.ConvertLineDelimiter.toMac.label=to CR (Classic &MacOS) -Editor.ConvertLineDelimiter.toMac.default.label=to CR (Classic &MacOS) [default] - -## Status line ## - -Editor.statusline.state.readonly.label=Read Only -Editor.statusline.state.writable.label=Writable -Editor.statusline.mode.insert.label=Insert -Editor.statusline.mode.overwrite.label=Overwrite -Editor.statusline.position.pattern={0} : {1} -Editor.statusline.error.label=? - -## Others ## - -AbstractMarkerAnnotationModel.connected=AbstractMarkerAnnotationModel.connected -AbstractMarkerAnnotationModel.createMarkerUpdater=AbstractMarkerAnnotationModel.createMarkerUpdater -AbstractMarkerAnnotationModel.removeAnnotations=AbstractMarkerAnnotationModel.removeAnnotations - -ResourceMarkerAnnotationModel.resourceChanged=ResourceMarkerAnnotationModel.resourceChanged - -WorkbenchChainedTextFontFieldEditor.defaultWorkbenchTextFont=<Using Workbench Text Font> - -FindReplace.title= Find/Replace -FindReplace.Find.label=&Find: -FindReplace.Replace.label=R&eplace With: -FindReplace.Direction=Direction -FindReplace.ForwardRadioButton.label=F&orward -FindReplace.BackwardRadioButton.label=&Backward -FindReplace.Scope=Scope -FindReplace.GlobalRadioButton.label=A&ll -FindReplace.SelectedRangeRadioButton.label=Selec&ted Lines -FindReplace.Options=Options -FindReplace.CaseCheckBox.label=&Case Sensitive -FindReplace.WrapCheckBox.label=Wra&p Search -FindReplace.WholeWordCheckBox.label=&Whole Word -FindReplace.IncrementalCheckBox.label=&Incremental -FindReplace.FindNextButton.label=Fi&nd -FindReplace.ReplaceFindButton.label=Replace/Fin&d -FindReplace.ReplaceSelectionButton.label=&Replace -FindReplace.ReplaceAllButton.label=Replace &All -FindReplace.CloseButton.label=Close -FindReplace.Status.noMatch.label=String Not Found -FindReplace.Status.replacement.label=1 Match replaced -FindReplace.Status.replacements.label={0} matches replaced - -FindNext.Status.noMatch.label=String Not Found - -MarkerRulerAction.addMarker=MarkerRulerAction.addMarker -MarkerRulerAction.getMarker=MarkerRulerAction.getMarker -MarkerRulerAction.removeMarkers=MarkerRulerAction.removeMarkers - -SelectMarkerRulerAction.getMarker=SelectMarkerRulerAction.getMarker -SelectMarkerRulerInfoAction.getMarker=SelectMarkerRulerInfoAction.getMarker diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorStatusLine.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorStatusLine.java deleted file mode 100644 index 0a3197c3819..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/EditorStatusLine.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.eclipse.ui.texteditor; - -import org.eclipse.swt.graphics.Image; - -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; - -/** - * An editor status line. - * The selection provider of the editor triggers the status line to be cleared. - * @since 2.1 - */ -class EditorStatusLine implements IEditorStatusLine { - - /** - * Clears the status line on selection changed. - */ - private class StatusLineClearer implements ISelectionChangedListener { - public void selectionChanged(SelectionChangedEvent event) { - fStatusLineManager.setErrorMessage(null); - - Assert.isTrue(this == fStatusLineClearer); - uninstallStatusLineClearer(); - } - }; - - /** The status line manager. */ - private final IStatusLineManager fStatusLineManager; - - /** The selection provider. */ - private final ISelectionProvider fSelectionProvider; - - /** The status line clearer, <code>null</code> if not installed. */ - private StatusLineClearer fStatusLineClearer; - - /** - * Constructor for EditorStatusLine. - */ - public EditorStatusLine(IStatusLineManager statusLineManager, ISelectionProvider selectionProvider) { - - Assert.isNotNull(statusLineManager); - Assert.isNotNull(selectionProvider); - - fStatusLineManager= statusLineManager; - fSelectionProvider= selectionProvider; - } - - /** - * Returns the status line manager. - */ - public IStatusLineManager getStatusLineManager() { - return fStatusLineManager; - } - - /** - * Returns the selection provider.
*/ - public ISelectionProvider getSelectionProvider() { - return fSelectionProvider; - } - - /* - * @see org.eclipse.ui.texteditor.IStatusLine#setMessage(boolean, String, Image)
*/ - public void setMessage(boolean error, String message, Image image) { - - if (error) - fStatusLineManager.setErrorMessage(image, message); - else - fStatusLineManager.setMessage(image, message); - - if (isMessageEmpty(message)) - uninstallStatusLineClearer(); - else - installStatusLineClearer(); - } - - private static boolean isMessageEmpty(String message) { - return message == null || message.trim().length() == 0; - } - - private void uninstallStatusLineClearer() { - if (fStatusLineClearer == null) - return; - - fSelectionProvider.removeSelectionChangedListener(fStatusLineClearer); - fStatusLineClearer= null; - } - - private void installStatusLineClearer() { - if (fStatusLineClearer != null) - return; - - StatusLineClearer statusLineClearer= new StatusLineClearer(); - fSelectionProvider.addSelectionChangedListener(statusLineClearer); - fStatusLineClearer= statusLineClearer; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java deleted file mode 100644 index 30a3222b89d..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindNextAction.java +++ /dev/null @@ -1,333 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; - -import org.eclipse.swt.graphics.Point; - -import org.eclipse.core.runtime.Platform; - -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.text.IFindReplaceTarget; - -import org.eclipse.ui.IEditorActionBarContributor; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.EditorActionBarContributor; -import org.eclipse.ui.plugin.AbstractUIPlugin; - - -/** - * An action which finds the next/previous occurrence of the last search or - * the current selection if present. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * @since 2.0 - */ -public class FindNextAction extends ResourceAction implements IUpdate { - - /** The action's target */ - private IFindReplaceTarget fTarget; - /** The part the action is bound to */ - private IWorkbenchPart fWorkbenchPart; - /** The workbench window */ - private IWorkbenchWindow fWorkbenchWindow; - /** The dialog settings to retrieve the last search */ - private IDialogSettings fDialogSettings; - /** The find history as initially given in the dialog settings. */ - private List fFindHistory= new ArrayList(); - /** The find string as initially given in the dialog settings. */ - private String fFindString; - /** The search direction as initially given in the dialog settings. */ - private boolean fForward; - /** The warpping flag as initially given in the dialog settings. */ - private boolean fWrapInit; - /** The case flag as initially given in the dialog settings. */ - private boolean fCaseInit; - /** The whole word flag as initially given in the dialog settings. */ - private boolean fWholeWordInit; - - /** - * Creates a new find/replace action for the given text editor. - * The action configures its visual representation from the given - * resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @param forward the search direction - * @see ResourceAction#ResourceAction - */ - public FindNextAction(ResourceBundle bundle, String prefix, IWorkbenchPart workbenchPart, boolean forward) { - super(bundle, prefix); - fWorkbenchPart= workbenchPart; - fForward= forward; - update(); - } - - /** - * Creates a new find/replace action for the given text editor. - * The action configures its visual representation from the given - * resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param workbenchWindow the workbench window - * @param forward the search direction - * @see ResourceAction#ResourceAction - * - * @deprecated use FindReplaceAction(ResourceBundle, String, IWorkbenchPart) instead - */ - public FindNextAction(ResourceBundle bundle, String prefix, IWorkbenchWindow workbenchWindow, boolean forward) { - super(bundle, prefix); - fWorkbenchWindow= workbenchWindow; - fForward= forward; - update(); - } - - /** - * Returns the find string based on the selection or the find history. - * @return the find string - */ - private String getFindString() { - String string= getSelectionString(); - - if (string == null && !fFindHistory.isEmpty()) - string= (String) fFindHistory.get(0); - - return string; - } - - /** - * Returns the status line manager of the active editor. - * @return the status line manager of the active editor - */ - private IStatusLineManager getStatusLineManager() { - - IEditorPart editor= fWorkbenchPart.getSite().getPage().getActiveEditor(); - if (editor == null) - return null; - - IEditorActionBarContributor contributor= editor.getEditorSite().getActionBarContributor(); - if (contributor instanceof EditorActionBarContributor) { - return ((EditorActionBarContributor) contributor).getActionBars().getStatusLineManager(); - } - return null; - } - - /** - * Sets the "no matches found" error message to the status line. - */ - private void statusError() { - fWorkbenchPart.getSite().getShell().getDisplay().beep(); - - IStatusLineManager manager= getStatusLineManager(); - if (manager == null) - return; - - manager.setErrorMessage(EditorMessages.getString("FindNext.Status.noMatch.label")); //$NON-NLS-1$ - manager.setMessage(""); //$NON-NLS-1$ - } - - /** - * Clears the status line. - */ - private void statusClear() { - IStatusLineManager manager= getStatusLineManager(); - if (manager == null) - return; - - manager.setErrorMessage(""); //$NON-NLS-1$ - manager.setMessage(""); //$NON-NLS-1$ - } - - /* - * @see IAction#run - */ - public void run() { - if (fTarget != null) { - readConfiguration(); - - fFindString= getFindString(); - if (fFindString == null) { - statusError(); - return; - } - - if (!findNext(fFindString, fForward, fCaseInit, fWrapInit, fWholeWordInit)) { - statusError(); - } else { - statusClear(); - } - - writeConfiguration(); - } - } - - /* - * @see IUpdate#update() - */ - public void update() { - - if (fWorkbenchPart == null && fWorkbenchWindow != null) - fWorkbenchPart= fWorkbenchWindow.getPartService().getActivePart(); - - if (fWorkbenchPart != null) - fTarget= (IFindReplaceTarget) fWorkbenchPart.getAdapter(IFindReplaceTarget.class); - else - fTarget= null; - - setEnabled(fTarget != null && fTarget.canPerformFind()); - } - - /** - * @see FindReplaceDialog#findIndex(String, int, boolean, boolean, boolean, boolean) - */ - private int findIndex(String findString, int startPosition, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord) { - - if (forwardSearch) { - if (wrapSearch) { - int index= fTarget.findAndSelect(startPosition, findString, true, caseSensitive, wholeWord); - if (index == -1) - index= fTarget.findAndSelect(-1, findString, true, caseSensitive, wholeWord); - return index; - } - return fTarget.findAndSelect(startPosition, findString, true, caseSensitive, wholeWord); - } - - // backward - if (wrapSearch) { - int index= fTarget.findAndSelect(startPosition - 1, findString, false, caseSensitive, wholeWord); - if (index == -1) { - index= fTarget.findAndSelect(-1, findString, false, caseSensitive, wholeWord); - } - return index; - } - return fTarget.findAndSelect(startPosition - 1, findString, false, caseSensitive, wholeWord); - } - - /** - * Returns whether the specified search string can be found using the given options. - * @param findString the string to search for - * @param forwardSearch the search direction - * @param caseSensitive should the search honor cases - * @param wrapSearch should the search wrap to the start/end if end/start reached - * @param wholeWord does the find string represent a complete word - * @return <code>true</code> if the find string can be found using the given options - */ - private boolean findNext(String findString, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord) { - - Point r= fTarget.getSelection(); - int findReplacePosition= r.x; - if (forwardSearch) - findReplacePosition += r.y; - - int index= findIndex(findString, findReplacePosition, forwardSearch, caseSensitive, wrapSearch, wholeWord); - - if (index != -1) - return true; - - return false; - } - - //--------------- configuration handling -------------- - - /** - * Returns the dialog settings object used to share state - * between several find/replace dialogs. - * - * @return the dialog settings to be used - */ - private IDialogSettings getDialogSettings() { - AbstractUIPlugin plugin= (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID); - IDialogSettings settings= plugin.getDialogSettings(); - fDialogSettings= settings.getSection(FindReplaceDialog.class.getName()); - if (fDialogSettings == null) - fDialogSettings= settings.addNewSection(FindReplaceDialog.class.getName()); - return fDialogSettings; - } - - /** - * Initializes itself from the dialog settings with the same state - * as at the previous invocation. - */ - private void readConfiguration() { - IDialogSettings s= getDialogSettings(); - - fWrapInit= s.getBoolean("wrap"); //$NON-NLS-1$ - fCaseInit= s.getBoolean("casesensitive"); //$NON-NLS-1$ - fWholeWordInit= s.getBoolean("wholeword"); //$NON-NLS-1$ - - String[] findHistory= s.getArray("findhistory"); //$NON-NLS-1$ - if (findHistory != null) { - fFindHistory.clear(); - for (int i= 0; i < findHistory.length; i++) - fFindHistory.add(findHistory[i]); - } - } - - /** - * Stores it current configuration in the dialog store. - */ - private void writeConfiguration() { - IDialogSettings s= getDialogSettings(); - - if (fFindString == null) - return; - - if (!fFindHistory.isEmpty() && fFindString.equals(fFindHistory.get(0))) - return; - - int index= fFindHistory.indexOf(fFindString); - if (index != -1) - fFindHistory.remove(index); - fFindHistory.add(0, fFindString); - - while (fFindHistory.size() > 8) - fFindHistory.remove(8); - String[] names= new String[fFindHistory.size()]; - fFindHistory.toArray(names); - s.put("findhistory", names); //$NON-NLS-1$ - } - - /** - * Returns the actual selection of the find replace target - */ - private String getSelectionString() { - - /* - * 1GF86V3: ITPUI:WINNT - Internal errors using Find/Replace Dialog - * Now uses TextUtilities rather than focussing on '\n' - */ - String selection= fTarget.getSelectionText(); - if (selection != null && selection.length() > 0) { - int[] info= TextUtilities.indexOf(TextUtilities.fgDelimiters, selection, 0); - if (info[0] > 0) - return selection.substring(0, info[0]); - else if (info[0] == -1) - return selection; - } - return null; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java deleted file mode 100644 index 8cb344485b7..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java +++ /dev/null @@ -1,244 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow; - - -/** - * An action which opens a Find/Replace dialog. - * The dialog while open, tracks the active workbench part - * and retargets itself to the active find/replace target. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * - * @see IFindReplaceTarget - */ -public class FindReplaceAction extends ResourceAction implements IUpdate { - - /** - * Represents the "global" find/replace dialog. It tracks the active - * part and retargets the find/replace dialog accordingly. The find/replace - * target is retrieved from the active part using - * <code>getAdapter(IFindReplaceTarget.class)</code>. - * <p> - * The stub has the same life cycle as the find/replace dialog. - */ - class FindReplaceDialogStub implements IPartListener, DisposeListener { - - private IWorkbenchPart fPart; - private IWorkbenchPart fPreviousPart; - private IFindReplaceTarget fPreviousTarget; - - private IWorkbenchWindow fWindow; - private FindReplaceDialog fDialog; - - /** - * Creates a new find/replace dialog accessor anchored at the given part site. - * @param site the part site - */ - public FindReplaceDialogStub(IWorkbenchPartSite site) { - - fWindow= site.getWorkbenchWindow(); - - fDialog= new FindReplaceDialog(site.getShell()); - fDialog.create(); - fDialog.getShell().addDisposeListener(this); - - IPartService service= fWindow.getPartService(); - service.addPartListener(this); - partActivated(service.getActivePart()); - } - - /** - * Returns the find/replace dialog. - * @return the find/replace dialog - */ - public FindReplaceDialog getDialog() { - return fDialog; - } - - /* - * @see IPartListener#partActivated(IWorkbenchPart) - */ - public void partActivated(IWorkbenchPart part) { - - IFindReplaceTarget target= part == null ? null : (IFindReplaceTarget) part.getAdapter(IFindReplaceTarget.class); - fPreviousPart= fPart; - fPart= target == null ? null : part; - - if (fPreviousTarget != target) { - fPreviousTarget= target; - if (fDialog != null) { - boolean isEditable= false; - if (fPart instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) fPart; - isEditable= !extension.isEditorInputReadOnly(); - } - fDialog.updateTarget(target, isEditable); - } - } - } - - /* - * @see IPartListener#partClosed(IWorkbenchPart) - */ - public void partClosed(IWorkbenchPart part) { - - if (part == fPreviousPart) { - fPreviousPart= null; - fPreviousTarget= null; - } - - if (part == fPart) - partActivated(null); - } - - /* - * @see DisposeListener#widgetDisposed(DisposeEvent) - */ - public void widgetDisposed(DisposeEvent event) { - - if (fgFindReplaceDialogStub == this) - fgFindReplaceDialogStub= null; - - if (fWindow != null) { - fWindow.getPartService().removePartListener(this); - fWindow= null; - } - fDialog= null; - fPart= null; - fPreviousPart= null; - fPreviousTarget= null; - } - - /* - * @see IPartListener#partOpened(IWorkbenchPart) - */ - public void partOpened(IWorkbenchPart part) {} - - /* - * @see IPartListener#partDeactivated(IWorkbenchPart) - */ - public void partDeactivated(IWorkbenchPart part) {} - - /* - * @see IPartListener#partBroughtToTop(IWorkbenchPart) - */ - public void partBroughtToTop(IWorkbenchPart part) {} - }; - - - /** Lister for disabling the dialog on editor close */ - private static FindReplaceDialogStub fgFindReplaceDialogStub; - /** The action's target */ - private IFindReplaceTarget fTarget; - /** The part the action is bound to */ - private IWorkbenchPart fWorkbenchPart; - /** The workbench window */ - private IWorkbenchWindow fWorkbenchWindow; - /** - * Indicates whether the find/replace target is editable - * @since 2.0 - */ - private boolean fIsTargetEditable= false; - - /** - * Creates a new find/replace action for the given text editor. - * The action configures its visual representation from the given - * resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @see ResourceAction#ResourceAction - */ - public FindReplaceAction(ResourceBundle bundle, String prefix, IWorkbenchPart workbenchPart) { - super(bundle, prefix); - fWorkbenchPart= workbenchPart; - update(); - } - - /** - * Creates a new find/replace action for the given text editor. - * The action configures its visual representation from the given - * resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param workbenchWindow the workbench window - * @see ResourceAction#ResourceAction - * - * @deprecated use FindReplaceAction(ResourceBundle, String, IWorkbenchPart) instead - */ - public FindReplaceAction(ResourceBundle bundle, String prefix, IWorkbenchWindow workbenchWindow) { - super(bundle, prefix); - fWorkbenchWindow= workbenchWindow; - update(); - } - - /* - * @see IAction#run - */ - public void run() { - if (fTarget != null) { - - if (fgFindReplaceDialogStub != null) { - Shell shell= fWorkbenchPart.getSite().getShell(); - FindReplaceDialog dialog= fgFindReplaceDialogStub.getDialog(); - if (dialog != null && shell != dialog.getParentShell()) { - fgFindReplaceDialogStub= null; // here to avoid timing issues - dialog.close(); - } - } - - if (fgFindReplaceDialogStub == null) - fgFindReplaceDialogStub= new FindReplaceDialogStub(fWorkbenchPart.getSite()); - - FindReplaceDialog dialog= fgFindReplaceDialogStub.getDialog(); - dialog.updateTarget(fTarget, fIsTargetEditable); - dialog.open(); - } - } - - /* - * @see IUpdate#update() - */ - public void update() { - - if (fWorkbenchPart == null && fWorkbenchWindow != null) - fWorkbenchPart= fWorkbenchWindow.getPartService().getActivePart(); - - if (fWorkbenchPart instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) fWorkbenchPart; - fIsTargetEditable= !extension.isEditorInputReadOnly(); - } - - if (fWorkbenchPart != null) - fTarget= (IFindReplaceTarget) fWorkbenchPart.getAdapter(IFindReplaceTarget.class); - else - fTarget= null; - - setEnabled(fTarget != null && fTarget.canPerformFind()); - -// if (fgFindReplaceDialogStub != null) { -// FindReplaceDialog dialog= fgFindReplaceDialogStub.getDialog(); -// dialog.updateTarget(fTarget, fIsTargetEditable); -// } - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java deleted file mode 100644 index 8b02cc1ce52..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceDialog.java +++ /dev/null @@ -1,1390 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.runtime.Platform; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.text.IFindReplaceTarget; -import org.eclipse.jface.text.IFindReplaceTargetExtension; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; - -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.plugin.AbstractUIPlugin; - - - -/** - * Find/Replace dialog. The dialog is opened on a particular - * target but can be re-targeted. Internally used by the <code>FindReplaceAction</code> - */ -class FindReplaceDialog extends Dialog { - - /** - * Updates the find replace dialog on activation changes. - */ - class ActivationListener extends ShellAdapter { - - /* - * @see ShellListener#shellActivated(ShellEvent) - */ - public void shellActivated(ShellEvent e) { - - String oldText= fFindField.getText(); // XXX workaround for 10766 - List oldList= new ArrayList(); - oldList.addAll(fFindHistory); - - readConfiguration(); - updateCombo(fFindField, fFindHistory); - - fFindField.removeModifyListener(fFindModifyListener); - if (!fFindHistory.equals(oldList) && !fFindHistory.isEmpty()) - fFindField.setText((String) fFindHistory.get(0)); - else - fFindField.setText(oldText); - fFindField.addModifyListener(fFindModifyListener); - - fActiveShell= (Shell) e.widget; - updateButtonState(); - if (getShell() == fActiveShell && !fFindField.isDisposed()) - fFindField.setFocus(); - } - - /* - * @see ShellListener#shellDeactivated(ShellEvent) - */ - public void shellDeactivated(ShellEvent e) { - storeSettings(); - - fGlobalRadioButton.setSelection(true); - fSelectedRangeRadioButton.setSelection(false); - - if (fTarget != null && (fTarget instanceof IFindReplaceTargetExtension)) - ((IFindReplaceTargetExtension) fTarget).setScope(null); - - fOldScope= null; - - fActiveShell= null; - updateButtonState(); - } - } - - /** - * Modify listener to update the search result in case of incremental search. - * @since 2.0 - */ - private class FindModifyListener implements ModifyListener { - - /* - * @see ModifyListener#modifyText(ModifyEvent) - */ - public void modifyText(ModifyEvent e) { - if (isIncrementalSearch()) { - if (fFindField.getText().equals("") && fTarget != null) { //$NON-NLS-1$ - // empty selection at base location - int offset= isForwardSearch() - ? fIncrementalBaseLocation.x + fIncrementalBaseLocation.y - : fIncrementalBaseLocation.x; - - fTarget.findAndSelect(offset, "", isForwardSearch(), isCaseSensitiveSearch(), isWholeWordSearch()); //$NON-NLS-1$ - } else { - performSearch(); - } - } - - updateButtonState(); - } - } - - /** The size of the dialogs search history. */ - private static final int HISTORY_SIZE= 5; - - private Point fLocation; - private Point fIncrementalBaseLocation; - private boolean fWrapInit, fCaseInit, fWholeWordInit, fForwardInit, fGlobalInit, fIncrementalInit; - private List fFindHistory; - private List fReplaceHistory; - private IRegion fOldScope; - - private boolean fIsTargetEditable; - private IFindReplaceTarget fTarget; - private Shell fParentShell; - private Shell fActiveShell; - - private ActivationListener fActivationListener= new ActivationListener(); - private ModifyListener fFindModifyListener= new FindModifyListener(); - - private Label fReplaceLabel, fStatusLabel; - private Button fForwardRadioButton, fGlobalRadioButton, fSelectedRangeRadioButton; - private Button fCaseCheckBox, fWrapCheckBox, fWholeWordCheckBox, fIncrementalCheckBox; - private Button fReplaceSelectionButton, fReplaceFindButton, fFindNextButton, fReplaceAllButton; - private Combo fFindField, fReplaceField; - private Rectangle fDialogPositionInit; - - private IDialogSettings fDialogSettings; - - /** - * Creates a new dialog with the given shell as parent. - * @param parentShell the parent shell - */ - public FindReplaceDialog(Shell parentShell) { - super(parentShell); - - fParentShell= null; - fTarget= null; - - fDialogPositionInit= null; - fFindHistory= new ArrayList(HISTORY_SIZE - 1); - fReplaceHistory= new ArrayList(HISTORY_SIZE - 1); - - fWrapInit= false; - fCaseInit= false; - fWholeWordInit= false; - fIncrementalInit= false; - fGlobalInit= true; - fForwardInit= true; - - readConfiguration(); - - setShellStyle(SWT.CLOSE | SWT.MODELESS | SWT.BORDER | SWT.TITLE); - setBlockOnOpen(false); - } - - /** - * Returns this dialog's parent shell. - * @return the dialog's parent shell - */ - public Shell getParentShell() { - return super.getParentShell(); - } - - - /** - * Returns <code>true</code> if control can be used - * - * @param control the control to be checked - * @return <code>true</code> if control can be used - */ - private boolean okToUse(Control control) { - return control != null && !control.isDisposed(); - } - - /* - * @see Window#create - */ - public void create() { - - super.create(); - - Shell shell= getShell(); - shell.addShellListener(fActivationListener); - if (fLocation != null) - shell.setLocation(fLocation); - - // set help context - WorkbenchHelp.setHelp(shell, IAbstractTextEditorHelpContextIds.FIND_REPLACE_DIALOG); - - // fill in combo contents - updateCombo(fFindField, fFindHistory); - updateCombo(fReplaceField, fReplaceHistory); - - // get find string - initFindStringFromSelection(); - - // set dialog position - if (fDialogPositionInit != null) - shell.setBounds(fDialogPositionInit); - - shell.setText(EditorMessages.getString("FindReplace.title")); //$NON-NLS-1$ - // shell.setImage(null); - } - - /** - * Create the button section of the find/replace dialog - * - * @param parent the parent composite - * @return the button section - */ - private Composite createButtonSection(Composite parent) { - - Composite panel= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= -2; - layout.makeColumnsEqualWidth= true; - panel.setLayout(layout); - - fFindNextButton= makeButton(panel, "FindReplace.FindNextButton.label", 102, true, new SelectionAdapter() { //$NON-NLS-1$ - public void widgetSelected(SelectionEvent e) { - if (isIncrementalSearch()) - initIncrementalBaseLocation(); - - performSearch(); - updateFindHistory(); - fFindNextButton.setFocus(); - } - }); - setGridData(fFindNextButton, GridData.FILL, true, GridData.FILL, false); - - fReplaceFindButton= makeButton(panel, "FindReplace.ReplaceFindButton.label", 103, false, new SelectionAdapter() { //$NON-NLS-1$ - public void widgetSelected(SelectionEvent e) { - performReplaceSelection(); - performSearch(); - updateFindAndReplaceHistory(); - fReplaceFindButton.setFocus(); - } - }); - setGridData(fReplaceFindButton, GridData.FILL, true, GridData.FILL, false); - - fReplaceSelectionButton= makeButton(panel, "FindReplace.ReplaceSelectionButton.label", 104, false, new SelectionAdapter() { //$NON-NLS-1$ - public void widgetSelected(SelectionEvent e) { - performReplaceSelection(); - updateFindAndReplaceHistory(); - fFindNextButton.setFocus(); - } - }); - setGridData(fReplaceSelectionButton, GridData.FILL, true, GridData.FILL, false); - - fReplaceAllButton= makeButton(panel, "FindReplace.ReplaceAllButton.label", 105, false, new SelectionAdapter() { //$NON-NLS-1$ - public void widgetSelected(SelectionEvent e) { - performReplaceAll(); - updateFindAndReplaceHistory(); - fFindNextButton.setFocus(); - } - }); - setGridData(fReplaceAllButton, GridData.FILL, true, GridData.FILL, false); - - // Make the all the buttons the same size as the Remove Selection button. - fReplaceAllButton.setEnabled(isEditable()); - - return panel; - } - - /** - * Creates the options configuration section of the find replace dialog. - * - * @param parent the parent composite - * @return the options configuration section - */ - private Composite createConfigPanel(Composite parent) { - - Composite panel= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.makeColumnsEqualWidth= true; - panel.setLayout(layout); - - Composite directionGroup= createDirectionGroup(panel); - setGridData(directionGroup, GridData.FILL, true, GridData.FILL, false); - Composite scopeGroup= createScopeGroup(panel); - setGridData(scopeGroup, GridData.FILL, true, GridData.FILL, false); - - Composite optionsGroup= createOptionsGroup(panel); - setGridData(optionsGroup, GridData.FILL, true, GridData.FILL, false); - GridData data= (GridData) optionsGroup.getLayoutData(); - data.horizontalSpan= 2; - optionsGroup.setLayoutData(data); - - return panel; - } - - /* - * @see Window#createContents - */ - protected Control createContents(Composite parent) { - - Composite panel= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 1; - layout.makeColumnsEqualWidth= true; - panel.setLayout(layout); - - Composite inputPanel= createInputPanel(panel); - setGridData(inputPanel, GridData.FILL, true, GridData.CENTER, false); - - Composite configPanel= createConfigPanel(panel); - setGridData(configPanel, GridData.FILL, true, GridData.CENTER, true); - - Composite buttonPanelB= createButtonSection(panel); - setGridData(buttonPanelB, GridData.FILL, true, GridData.CENTER, false); - - Composite statusBar= createStatusAndCloseButton(panel); - setGridData(statusBar, GridData.FILL, true, GridData.CENTER, false); - - updateButtonState(); - - return panel; - } - - /** - * Creates the direction defining part of the options defining section - * of the find replace dialog. - * - * @param parent the parent composite - * @return the direction defining part - */ - private Composite createDirectionGroup(Composite parent) { - - Composite panel= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.marginWidth= 0; - layout.marginHeight= 0; - panel.setLayout(layout); - - Group group= new Group(panel, SWT.SHADOW_ETCHED_IN); - group.setText(EditorMessages.getString("FindReplace.Direction")); //$NON-NLS-1$ - GridLayout groupLayout= new GridLayout(); - group.setLayout(groupLayout); - group.setLayoutData(new GridData(GridData.FILL_BOTH)); - - SelectionListener selectionListener= new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - if (isIncrementalSearch()) - initIncrementalBaseLocation(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - }; - - fForwardRadioButton= new Button(group, SWT.RADIO | SWT.LEFT); - fForwardRadioButton.setText(EditorMessages.getString("FindReplace.ForwardRadioButton.label")); //$NON-NLS-1$ - setGridData(fForwardRadioButton, GridData.BEGINNING, false, GridData.CENTER, false); - fForwardRadioButton.addSelectionListener(selectionListener); - - Button backwardRadioButton= new Button(group, SWT.RADIO | SWT.LEFT); - backwardRadioButton.setText(EditorMessages.getString("FindReplace.BackwardRadioButton.label")); //$NON-NLS-1$ - setGridData(backwardRadioButton, GridData.BEGINNING, false, GridData.CENTER, false); - backwardRadioButton.addSelectionListener(selectionListener); - - backwardRadioButton.setSelection(!fForwardInit); - fForwardRadioButton.setSelection(fForwardInit); - - return panel; - } - - /** - * Creates the scope defining part of the find replace dialog. - * - * @param parent the parent composite - * @return the scope defining part - * @since 2.0 - */ - private Composite createScopeGroup(Composite parent) { - - Composite panel= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(); - layout.marginWidth= 0; - layout.marginHeight= 0; - panel.setLayout(layout); - - Group group= new Group(panel, SWT.SHADOW_ETCHED_IN); - group.setText(EditorMessages.getString("FindReplace.Scope")); //$NON-NLS-1$ - GridLayout groupLayout= new GridLayout(); - group.setLayout(groupLayout); - group.setLayoutData(new GridData(GridData.FILL_BOTH)); - - fGlobalRadioButton= new Button(group, SWT.RADIO | SWT.LEFT); - fGlobalRadioButton.setText(EditorMessages.getString("FindReplace.GlobalRadioButton.label")); //$NON-NLS-1$ - setGridData(fGlobalRadioButton, GridData.BEGINNING, false, GridData.CENTER, false); - fGlobalRadioButton.setSelection(fGlobalInit); - fGlobalRadioButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - if (!fGlobalRadioButton.getSelection()) - return; - - useSelectedLines(false); - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - fSelectedRangeRadioButton= new Button(group, SWT.RADIO | SWT.LEFT); - fSelectedRangeRadioButton.setText(EditorMessages.getString("FindReplace.SelectedRangeRadioButton.label")); //$NON-NLS-1$ - setGridData(fSelectedRangeRadioButton, GridData.BEGINNING, false, GridData.CENTER, false); - fSelectedRangeRadioButton.setSelection(!fGlobalInit); - fSelectedRangeRadioButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - if (!fSelectedRangeRadioButton.getSelection()) - return; - - useSelectedLines(true); - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - return panel; - } - - /** - * Tells the dialog to perform searches only in the scope given by the actually selected lines. - * @param selectedLines <code>true</code> if selected lines should be used - * @since 2.0 - */ - private void useSelectedLines(boolean selectedLines) { - if (isIncrementalSearch()) - initIncrementalBaseLocation(); - - if (fTarget == null || !(fTarget instanceof IFindReplaceTargetExtension)) - return; - - IFindReplaceTargetExtension extensionTarget= (IFindReplaceTargetExtension) fTarget; - - if (selectedLines) { - - IRegion scope; - if (fOldScope == null) { - Point lineSelection= extensionTarget.getLineSelection(); - scope= new Region(lineSelection.x, lineSelection.y); - } else { - scope= fOldScope; - fOldScope= null; - } - - int offset= isForwardSearch() - ? scope.getOffset() - : scope.getOffset() + scope.getLength(); - - extensionTarget.setSelection(offset, 0); - extensionTarget.setScope(scope); - } else { - fOldScope= extensionTarget.getScope(); - extensionTarget.setScope(null); - } - } - - /** - * Create the panel where the user specifies the text to search - * for and the optional replacement text - * - * @param parent the parent composite - * @return the input panel - */ - private Composite createInputPanel(Composite parent) { - - ModifyListener listener= new ModifyListener() { - public void modifyText(ModifyEvent e) { - updateButtonState(); - } - }; - - Composite panel= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - panel.setLayout(layout); - - Label findLabel= new Label(panel, SWT.LEFT); - findLabel.setText(EditorMessages.getString("FindReplace.Find.label")); //$NON-NLS-1$ - setGridData(findLabel, GridData.BEGINNING, false, GridData.CENTER, false); - - fFindField= new Combo(panel, SWT.DROP_DOWN | SWT.BORDER); - setGridData(fFindField, GridData.FILL, true, GridData.CENTER, false); - fFindField.addModifyListener(fFindModifyListener); - - fReplaceLabel= new Label(panel, SWT.LEFT); - fReplaceLabel.setText(EditorMessages.getString("FindReplace.Replace.label")); //$NON-NLS-1$ - setGridData(fReplaceLabel, GridData.BEGINNING, false, GridData.CENTER, false); - - fReplaceField= new Combo(panel, SWT.DROP_DOWN | SWT.BORDER); - setGridData(fReplaceField, GridData.FILL, true, GridData.CENTER, false); - fReplaceField.addModifyListener(listener); - - return panel; - } - - /** - * Creates the functional options part of the options defining - * section of the find replace dialog. - * - * @param the parent composite - * @return the options group - */ - private Composite createOptionsGroup(Composite parent) { - - Composite panel= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.marginWidth= 0; - layout.marginHeight= 0; - panel.setLayout(layout); - - Group group= new Group(panel, SWT.SHADOW_NONE); - group.setText(EditorMessages.getString("FindReplace.Options")); //$NON-NLS-1$ - GridLayout groupLayout= new GridLayout(); - groupLayout.numColumns= 2; - groupLayout.makeColumnsEqualWidth= true; - group.setLayout(groupLayout); - group.setLayoutData(new GridData(GridData.FILL_BOTH)); - - SelectionListener selectionListener= new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - storeSettings(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - }; - - fCaseCheckBox= new Button(group, SWT.CHECK | SWT.LEFT); - fCaseCheckBox.setText(EditorMessages.getString("FindReplace.CaseCheckBox.label")); //$NON-NLS-1$ - setGridData(fCaseCheckBox, GridData.BEGINNING, false, GridData.CENTER, false); - fCaseCheckBox.setSelection(fCaseInit); - fCaseCheckBox.addSelectionListener(selectionListener); - - fWrapCheckBox= new Button(group, SWT.CHECK | SWT.LEFT); - fWrapCheckBox.setText(EditorMessages.getString("FindReplace.WrapCheckBox.label")); //$NON-NLS-1$ - setGridData(fWrapCheckBox, GridData.BEGINNING, false, GridData.CENTER, false); - fWrapCheckBox.setSelection(fWrapInit); - fWrapCheckBox.addSelectionListener(selectionListener); - - fWholeWordCheckBox= new Button(group, SWT.CHECK | SWT.LEFT); - fWholeWordCheckBox.setText(EditorMessages.getString("FindReplace.WholeWordCheckBox.label")); //$NON-NLS-1$ - setGridData(fWholeWordCheckBox, GridData.BEGINNING, false, GridData.CENTER, false); - fWholeWordCheckBox.setSelection(fWholeWordInit); - fWholeWordCheckBox.addSelectionListener(selectionListener); - - fIncrementalCheckBox= new Button(group, SWT.CHECK | SWT.LEFT); - fIncrementalCheckBox.setText(EditorMessages.getString("FindReplace.IncrementalCheckBox.label")); //$NON-NLS-1$ - setGridData(fIncrementalCheckBox, GridData.BEGINNING, false, GridData.CENTER, false); - fIncrementalCheckBox.setSelection(fIncrementalInit); - fIncrementalCheckBox.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - if (isIncrementalSearch()) - initIncrementalBaseLocation(); - - storeSettings(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - return panel; - } - - /** - * Creates the status and close section of the dialog. - * - * @param parent the parent composite - * @return the status and close button - */ - private Composite createStatusAndCloseButton(Composite parent) { - - Composite panel= new Composite(parent, SWT.NULL); - GridLayout layout= new GridLayout(); - layout.numColumns= 2; - layout.marginWidth= 0; - layout.marginHeight= 0; - panel.setLayout(layout); - - fStatusLabel= new Label(panel, SWT.LEFT); - setGridData(fStatusLabel, GridData.FILL, true, GridData.CENTER, false); - - String label= EditorMessages.getString("FindReplace.CloseButton.label"); //$NON-NLS-1$ - Button closeButton= createButton(panel, 101, label, false); - setGridData(closeButton, GridData.END, false, GridData.END, false); - - return panel; - } - - /* - * @see Dialog#buttonPressed - */ - protected void buttonPressed(int buttonID) { - if (buttonID == 101) - close(); - } - - - - // ------- action invocation --------------------------------------- - - /** - * Returns the position of the specified search string, or <code>-1</code> if the string can - * not be found when searching using the given options. - * - * @param findString the string to search for - * @param startPosition the position at which to start the search - * @param forwardSearch the direction of the search - * @param caseSensitive should the search be case sensitive - * @param wrapSearch should the search wrap to the start/end if arrived at the end/start - * @param wholeWord does the search string represent a complete word - * @return the occurrence of the find string following the options or <code>-1</code> if nothing found - */ - private int findIndex(String findString, int startPosition, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord) { - - if (forwardSearch) { - if (wrapSearch) { - int index= fTarget.findAndSelect(startPosition, findString, true, caseSensitive, wholeWord); - if (index == -1) - index= fTarget.findAndSelect(-1, findString, true, caseSensitive, wholeWord); - return index; - } - return fTarget.findAndSelect(startPosition, findString, true, caseSensitive, wholeWord); - } - - // backward - if (wrapSearch) { - int index= fTarget.findAndSelect(startPosition - 1, findString, false, caseSensitive, wholeWord); - if (index == -1) { - index= fTarget.findAndSelect(-1, findString, false, caseSensitive, wholeWord); - } - return index; - } - return fTarget.findAndSelect(startPosition - 1, findString, false, caseSensitive, wholeWord); - } - - /** - * Returns whether the specified search string can be found using the given options. - * - * @param findString the string to search for - * @param forwardSearch the direction of the search - * @param caseSensitive should the search be case sensitive - * @param wrapSearch should the search wrap to the start/end if arrived at the end/start - * @param wholeWord does the search string represent a complete word - * @param incremental is this an incremental search - * @param global is the search scope the whoel document - * @return <code>true</code> if the search string can be found using the given options - * @since 2.0 - */ - private boolean findNext(String findString, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord, boolean incremental, boolean global) { - - if (fTarget == null) - return false; - - Point r= fTarget.getSelection(); - int findReplacePosition= r.x; - if (forwardSearch) - findReplacePosition += r.y; - - if (incremental) - findReplacePosition= forwardSearch - ? fIncrementalBaseLocation.x + fIncrementalBaseLocation.y - : fIncrementalBaseLocation.x; - - int index= findIndex(findString, findReplacePosition, forwardSearch, caseSensitive, wrapSearch, wholeWord); - - if (index != -1) - return true; - - return false; - } - - /** - * Returns the dialog's boundaries. - * @return the dialog's boundaries - */ - private Rectangle getDialogBoundaries() { - if (okToUse(getShell())) { - return getShell().getBounds(); - } else { - return fDialogPositionInit; - } - } - - /** - * Returns the dialog's history. - * @return the dialog's history - */ - private List getFindHistory() { - return fFindHistory; - } - - // ------- accessors --------------------------------------- - - /** - * Retrieves the string to search for from the appriopriate text input field and returns it. - * @return the search string - */ - private String getFindString() { - if (okToUse(fFindField)) { - return fFindField.getText(); - } - return ""; //$NON-NLS-1$ - } - - /** - * Returns the dialog's replace history. - * @return the dialog's replace history - */ - private List getReplaceHistory() { - return fReplaceHistory; - } - - /** - * Retrieves the replacement string from the appriopriate text input field and returns it. - * @return the replacement string - */ - private String getReplaceString() { - if (okToUse(fReplaceField)) { - return fReplaceField.getText(); - } - return ""; //$NON-NLS-1$ - } - - // ------- init / close --------------------------------------- - - /** - * Returns the actual selection of the find replace target - * @return the selection of the target - */ - private String getSelectionString() { - - /* - * 1GF86V3: ITPUI:WINNT - Internal errors using Find/Replace Dialog - * Now uses TextUtilities rather than focussing on '\n' - */ - String selection= fTarget.getSelectionText(); - if (selection != null && selection.length() > 0) { - int[] info= TextUtilities.indexOf(TextUtilities.fgDelimiters, selection, 0); - if (info[0] > 0) - return selection.substring(0, info[0]); - else if (info[0] == -1) - return selection; - } - return null; - } - - /* - * @see Window#close() - */ - public boolean close() { - handleDialogClose(); - return super.close(); - } - - /** - * Removes focus changed listener from browser and stores settings for re-open. - */ - private void handleDialogClose() { - - // remove listeners - if (fParentShell != null) { - fParentShell.removeShellListener(fActivationListener); - fParentShell= null; - } - - getShell().removeShellListener(fActivationListener); - - // store current settings in case of re-open - storeSettings(); - - if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).endSession(); - - // prevent leaks - fActiveShell= null; - fTarget= null; - } - - /** - * Stores the current state in the dialog settings. - * @since 2.0 - */ - private void storeSettings() { - fDialogPositionInit= getDialogBoundaries(); - fWrapInit= isWrapSearch(); - fWholeWordInit= isWholeWordSearch(); - fCaseInit= isCaseSensitiveSearch(); - fIncrementalInit= isIncrementalSearch(); - fForwardInit= isForwardSearch(); - - writeConfiguration(); - } - - /** - * Initializes the string to search for and the appropriate - * text inout field based on the selection found in the - * action's target. - */ - private void initFindStringFromSelection() { - if (fTarget != null && okToUse(fFindField)) { - String selection= getSelectionString(); - fFindField.removeModifyListener(fFindModifyListener); - if (selection != null) { - fFindField.setText(selection); - if (!selection.equals(fTarget.getSelectionText())) { - useSelectedLines(true); - fGlobalRadioButton.setSelection(false); - fSelectedRangeRadioButton.setSelection(true); - } - } else { - if ("".equals(fFindField.getText())) { //$NON-NLS-1$ - if (fFindHistory.size() > 0) - fFindField.setText((String) fFindHistory.get(0)); - else - fFindField.setText(""); //$NON-NLS-1$ - } - } - fFindField.addModifyListener(fFindModifyListener); - } - } - - /** - * Initializes the anchor used as starting point for incremental searching. - * @since 2.0 - */ - private void initIncrementalBaseLocation() { - if (fTarget != null && isIncrementalSearch()) { - fIncrementalBaseLocation= fTarget.getSelection(); - } else { - fIncrementalBaseLocation= new Point(0, 0); - } - } - - // ------- history --------------------------------------- - - /** - * Initialize the find history. - * @param history the history to be initialized - * @param init the initialization data - */ - private void initHistory(List history, List init) { - history.clear(); - for (int i= 0; i < init.size() && i < HISTORY_SIZE - 1; i++) { - history.add(init.get(i)); - } - } - - /** - * Retrieves and returns the option case sensitivity from the appropriate check box. - * @return <code>true</code> if case sensitive - */ - private boolean isCaseSensitiveSearch() { - if (okToUse(fCaseCheckBox)) { - return fCaseCheckBox.getSelection(); - } - return fCaseInit; - } - - /** - * Retrieves and returns the option search direction from the appropriate check box. - * @return <code>true</code> if searching forward - */ - private boolean isForwardSearch() { - if (okToUse(fForwardRadioButton)) { - return fForwardRadioButton.getSelection(); - } - return fForwardInit; - } - - /** - * Retrieves and returns the option global scope from the appropriate check box. - * @return <code>true</code> if searching globally - * @since 2.0 - */ - private boolean isGlobalSearch() { - if (okToUse(fGlobalRadioButton)) { - return fGlobalRadioButton.getSelection(); - } - return fGlobalInit; - } - - /** - * Retrieves and returns the option search whole words from the appropriate check box. - * @return <code>true</code> if searching for whole words - */ - private boolean isWholeWordSearch() { - if (okToUse(fWholeWordCheckBox)) { - return fWholeWordCheckBox.getSelection(); - } - return fWholeWordInit; - } - - /** - * Retrieves and returns the option wrap search from the appropriate check box. - * @return <code>true</code> if wrapping while searching - */ - private boolean isWrapSearch() { - if (okToUse(fWrapCheckBox)) { - return fWrapCheckBox.getSelection(); - } - return fWrapInit; - } - - /** - * Retrieves and returns the option incremental search from the appropriate check box. - * @return <code>true</code> if incremental search - * @since 2.0 - */ - private boolean isIncrementalSearch() { - if (okToUse(fIncrementalCheckBox)) { - return fIncrementalCheckBox.getSelection(); - } - return fIncrementalInit; - } - - /** - * Creates a button. - * @param parent the parent control - * @param key the key to lookup the button label - * @param id the button id - * @param dfltButton is this button the default button - * @param listener a button pressed listener - * @return teh new button - */ - private Button makeButton(Composite parent, String key, int id, boolean dfltButton, SelectionListener listener) { - String label= EditorMessages.getString(key); - Button b= createButton(parent, id, label, dfltButton); - b.addSelectionListener(listener); - return b; - } - - /** - * Returns the status line manager of the active editor or <code>null</code> if there is no such editor. - * @return the status line manager of the active editor - */ - private IEditorStatusLine getStatusLineManager() { - AbstractUIPlugin plugin= (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID); - IWorkbenchWindow window= plugin.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) - return null; - - IWorkbenchPage page= window.getActivePage(); - if (page == null) - return null; - - IEditorPart editor= page.getActiveEditor(); - if (editor == null) - return null; - - return (IEditorStatusLine) editor.getAdapter(IEditorStatusLine.class); - } - - /** - * Sets the given error message in the status line. - * @param message the error message - */ - private void statusMessage(boolean error, String message) { - fStatusLabel.setText(message); - - IEditorStatusLine statusLine= getStatusLineManager(); - if (statusLine != null) - statusLine.setMessage(error, message, null); - - if (error) - getShell().getDisplay().beep(); - } - - /** - * Sets the given error message in the status line. - * @param message the message - */ - private void statusError(String message) { - statusMessage(true, message); - } - - /** - * Sets the given message in the status line. - * @param message the message - */ - private void statusMessage(String message) { - statusMessage(false, message); - } - - /** - * Replaces all occurrences of the user's findString with - * the replace string. Indicate to the user the number of replacements - * that occur. - */ - private void performReplaceAll() { - - int replaceCount= 0; - String replaceString= getReplaceString(); - String findString= getFindString(); - - if (replaceString == null) - replaceString= ""; //$NON-NLS-1$ - - if (findString != null && findString.length() > 0) { - - replaceCount= replaceAll(findString, replaceString, isForwardSearch(), isCaseSensitiveSearch(), isWrapSearch(), isWholeWordSearch(), isGlobalSearch()); - - if (replaceCount != 0) { - if (replaceCount == 1) { // not plural - statusMessage(EditorMessages.getString("FindReplace.Status.replacement.label")); //$NON-NLS-1$ - } else { - String msg= EditorMessages.getString("FindReplace.Status.replacements.label"); //$NON-NLS-1$ - msg= MessageFormat.format(msg, new Object[] {String.valueOf(replaceCount)}); - statusMessage(msg); - } - } else { - statusError(EditorMessages.getString("FindReplace.Status.noMatch.label")); //$NON-NLS-1$ - } - } - - updateButtonState(); - } - - /** - * Replaces the current selection of the target with the user's - * replace string. - */ - private void performReplaceSelection() { - - String replaceString= getReplaceString(); - if (replaceString == null) - replaceString= ""; //$NON-NLS-1$ - - fTarget.replaceSelection(replaceString); - updateButtonState(); - } - - /** - * Locates the user's findString in the text of the target. - */ - private void performSearch() { - - String findString= getFindString(); - - if (findString != null && findString.length() > 0) { - - boolean somethingFound= findNext(findString, isForwardSearch(), isCaseSensitiveSearch(), isWrapSearch(), isWholeWordSearch(), isIncrementalSearch(), isGlobalSearch()); - - if (somethingFound) { - statusMessage(""); //$NON-NLS-1$ - } else { - statusError(EditorMessages.getString("FindReplace.Status.noMatch.label")); //$NON-NLS-1$ - } - } - - updateButtonState(); - } - - /** - * Replaces all occurrences of the user's findString with - * the replace string. Returns the number of replacements - * that occur. - * - * @param findString the string to search for - * @param replaceString the replacement string - * @param forwardSearch the search direction - * @param caseSensitive should the search be case sensitive - * @param wrapSearch should search wrap to start/end if end/start is reached - * @param wholeWord does the search string represent a complete word - * @param global is the search performed globally - * @return the number of occurrences - * @since 2.0 - */ - private int replaceAll(String findString, String replaceString, boolean forwardSearch, boolean caseSensitive, boolean wrapSearch, boolean wholeWord, boolean global) { - - int replaceCount= 0; - int findReplacePosition= 0; - - if (wrapSearch) { // search the whole text - findReplacePosition= 0; - forwardSearch= true; - } else if (fTarget.getSelectionText() != null) { - // the cursor is set to the end or beginning of the selected text - Point selection= fTarget.getSelection(); - findReplacePosition= selection.x; - } - - if (fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).setReplaceAllMode(true); - - try { - int index= 0; - while (index != -1) { - index= fTarget.findAndSelect(findReplacePosition, findString, forwardSearch, caseSensitive, wholeWord); - if (index != -1) { // substring not contained from current position - if (forwardSearch) - findReplacePosition= index + replaceString.length(); - else - findReplacePosition= index - replaceString.length(); - fTarget.replaceSelection(replaceString); - replaceCount++; - } - } - } finally { - if (fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).setReplaceAllMode(false); - } - - return replaceCount; - } - - // ------- ui creation --------------------------------------- - - /** - * Attaches the given layout specification to the <code>component</code> - * - * @param component the component - * @param horizontalAlignment horizontal alignment - * @param grabExcessHorizontalSpace grab excess horizontal space - * @param verticalAlignment vertical alignment - * @param grabExcessVerticalSpace grab excess vertical space - */ - private void setGridData(Control component, int horizontalAlignment, boolean grabExcessHorizontalSpace, int verticalAlignment, boolean grabExcessVerticalSpace) { - GridData gd= new GridData(); - gd.horizontalAlignment= horizontalAlignment; - gd.grabExcessHorizontalSpace= grabExcessHorizontalSpace; - gd.verticalAlignment= verticalAlignment; - gd.grabExcessVerticalSpace= grabExcessVerticalSpace; - component.setLayoutData(gd); - } - - /** - * Updates the enabled state of the buttons. - */ - private void updateButtonState() { - if (okToUse(getShell()) && okToUse(fFindNextButton)) { - String selectedText= null; - if (fTarget != null) { - selectedText= fTarget.getSelectionText(); - } - - boolean selection= (selectedText != null && selectedText.length() > 0); - - boolean enable= fTarget != null && (fActiveShell == fParentShell || fActiveShell == getShell()); - String str= getFindString(); - boolean findString= (str != null && str.length() > 0); - - fFindNextButton.setEnabled(enable && findString); - fReplaceSelectionButton.setEnabled(enable && isEditable() && selection); - fReplaceFindButton.setEnabled(enable && isEditable() && findString && selection); - fReplaceAllButton.setEnabled(enable && isEditable() && findString); - } - } - - /** - * Updates the given combo with the given content. - * @param combo combo to be updated - * @param content to be put into the combo - */ - private void updateCombo(Combo combo, List content) { - combo.removeAll(); - for (int i= 0; i < content.size(); i++) { - combo.add(content.get(i).toString()); - } - } - - // ------- open / reopen --------------------------------------- - - /** - * Called after executed find/replace action to update the history - */ - private void updateFindAndReplaceHistory() { - updateFindHistory(); - if (okToUse(fReplaceField)) { - updateHistory(fReplaceField, fReplaceHistory); - } - - } - - /** - * Called after executed find action to update the history - */ - private void updateFindHistory() { - if (okToUse(fFindField)) { - fFindField.removeModifyListener(fFindModifyListener); - updateHistory(fFindField, fFindHistory); - fFindField.addModifyListener(fFindModifyListener); - } - } - - /** - * Updates the combo with the history. - * @param combo to be updated - * @param history to be put into the combo - */ - private void updateHistory(Combo combo, List history) { - String findString= combo.getText(); - int index= history.indexOf(findString); - if (index != 0) { - if (index != -1) { - history.remove(index); - } - history.add(0, findString); - updateCombo(combo, history); - combo.setText(findString); - } - } - - /** - * Returns whether the target is editable - * @return <code>true</code> if target is editable - */ - private boolean isEditable() { - boolean isEditable= (fTarget == null ? false : fTarget.isEditable()); - return fIsTargetEditable && isEditable; - } - - /** - * Updates this dialog because of a different target. - * @param target the new target - * @param isTargetEditable <code>true</code> if the new target can be modifed - * @since 2.0 - */ - public void updateTarget(IFindReplaceTarget target, boolean isTargetEditable) { - - fIsTargetEditable= isTargetEditable; - - if (target != fTarget) { - if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).endSession(); - - fTarget= target; - - if (fTarget != null && fTarget instanceof IFindReplaceTargetExtension) { - ((IFindReplaceTargetExtension) fTarget).beginSession(); - - fGlobalInit= true; - fGlobalRadioButton.setSelection(fGlobalInit); - fSelectedRangeRadioButton.setSelection(!fGlobalInit); - } - } - - if (okToUse(fReplaceLabel)) { - fReplaceLabel.setEnabled(isEditable()); - fReplaceField.setEnabled(isEditable()); - initFindStringFromSelection(); - initIncrementalBaseLocation(); - updateButtonState(); - } - } - - /** - * Sets the parent shell of this dialog to be the given shell. - * - * @param shell the new parent shell - */ - public void setParentShell(Shell shell) { - if (shell != fParentShell) { - - if (fParentShell != null) - fParentShell.removeShellListener(fActivationListener); - - fParentShell= shell; - fParentShell.addShellListener(fActivationListener); - } - - fActiveShell= shell; - } - - - //--------------- configuration handling -------------- - - /** - * Returns the dialog settings object used to share state - * between several find/replace dialogs. - * - * @return the dialog settings to be used - */ - private IDialogSettings getDialogSettings() { - AbstractUIPlugin plugin= (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID); - IDialogSettings settings= plugin.getDialogSettings(); - fDialogSettings= settings.getSection(getClass().getName()); - if (fDialogSettings == null) - fDialogSettings= settings.addNewSection(getClass().getName()); - return fDialogSettings; - } - - /** - * Initializes itself from the dialog settings with the same state - * as at the previous invocation. - */ - private void readConfiguration() { - IDialogSettings s= getDialogSettings(); - - try { - int x= s.getInt("x"); //$NON-NLS-1$ - int y= s.getInt("y"); //$NON-NLS-1$ - fLocation= new Point(x, y); - } catch (NumberFormatException e) { - fLocation= null; - } - - fWrapInit= s.getBoolean("wrap"); //$NON-NLS-1$ - fCaseInit= s.getBoolean("casesensitive"); //$NON-NLS-1$ - fWholeWordInit= s.getBoolean("wholeword"); //$NON-NLS-1$ - fIncrementalInit= s.getBoolean("incremental"); //$NON-NLS-1$ - - String[] findHistory= s.getArray("findhistory"); //$NON-NLS-1$ - if (findHistory != null) { - List history= getFindHistory(); - history.clear(); - for (int i= 0; i < findHistory.length; i++) - history.add(findHistory[i]); - } - - String[] replaceHistory= s.getArray("replacehistory"); //$NON-NLS-1$ - if (replaceHistory != null) { - List history= getReplaceHistory(); - history.clear(); - for (int i= 0; i < replaceHistory.length; i++) - history.add(replaceHistory[i]); - } - } - - /** - * Stores it current configuration in the dialog store. - */ - private void writeConfiguration() { - IDialogSettings s= getDialogSettings(); - - Point location= getShell().getLocation(); - s.put("x", location.x); //$NON-NLS-1$ - s.put("y", location.y); //$NON-NLS-1$ - - s.put("wrap", fWrapInit); //$NON-NLS-1$ - s.put("casesensitive", fCaseInit); //$NON-NLS-1$ - s.put("wholeword", fWholeWordInit); //$NON-NLS-1$ - s.put("incremental", fIncrementalInit); //$NON-NLS-1$ - - List history= getFindHistory(); - while (history.size() > 8) - history.remove(8); - String[] names= new String[history.size()]; - history.toArray(names); - s.put("findhistory", names); //$NON-NLS-1$ - - history= getReplaceHistory(); - while (history.size() > 8) - history.remove(8); - names= new String[history.size()]; - history.toArray(names); - s.put("replacehistory", names); //$NON-NLS-1$ - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/GotoLineAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/GotoLineAction.java deleted file mode 100644 index 9817d23e5ef..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/GotoLineAction.java +++ /dev/null @@ -1,186 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.text.MessageFormat; -import java.util.ResourceBundle; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.dialogs.IInputValidator; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -import org.eclipse.ui.IWorkbenchPage; - - -/** - * Action for jumping to a particular line if the editor's text viewer. - * The user is requested to enter the line number into an input dialog. - * The action is initially associated with a text editor via the constructor, - * but that can be subsequently changed using <code>setEditor</code>. - * <p> - * The following keys, prepended by the given option prefix, - * are used for retrieving resources from the given bundle: - * <ul> - * <li><code>"dialog.invalid_range"</code> - to indicate an invalid line number</li> - * <li><code>"dialog.invalid_input"</code> - to indicate an invalid line number format</li> - * <li><code>"dialog.title"</code> - the input dialog's title</li> - * <li><code>"dialog.message"</code> - the input dialog's message</li> - * </ul> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - */ -public class GotoLineAction extends TextEditorAction { - - /** - * Validates whether the text found in the input field of the - * dialog forms a valid line number. A number is valid if it is - * one to which can be jumped. - */ - class NumberValidator implements IInputValidator { - - /* - * @see IInputValidator#isValid(String) - */ - public String isValid(String input) { - - if (input == null || input.length() == 0) - return " "; //$NON-NLS-1$ - - try { - int i= Integer.parseInt(input); - if (i <= 0 || fLastLine < i) - return fBundle.getString(fPrefix + "dialog.invalid_range"); //$NON-NLS-1$ - - } catch (NumberFormatException x) { - return fBundle.getString(fPrefix + "dialog.invalid_input"); //$NON-NLS-1$ - } - - return null; - } - }; - - /** - * Standard input dialog which additionally sets the focus to the - * text input field. Workaround for <code>InputDialog</code> issue. - * 1GIJZOO: ITPSRCEDIT:ALL - Gotodialog's edit field has no initial focus - * @since 2.0 - */ - class GotoLineDialog extends InputDialog { - - /* - * @see InputDialog#InputDialog - */ - public GotoLineDialog(Shell parent, String title, String message, String initialValue, IInputValidator validator) { - super(parent, title, message, initialValue, validator); - } - - /* - * @see InputDialog#createDialogArea(Composite) - */ - protected Control createDialogArea(Composite parent) { - Control result= super.createDialogArea(parent); - getText().setFocus(); - return result; - } - }; - - /** The biggest valid line number of the presented document */ - private int fLastLine; - /** This action's resource bundle */ - private ResourceBundle fBundle; - /** This action's prefix used for accessing the resource bundle */ - private String fPrefix; - - /** - * Creates a new action for the given text editor. The action configures its - * visual representation from the given resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @see ResourceAction#ResourceAction - */ - public GotoLineAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - fBundle= bundle; - fPrefix= prefix; - } - - /** - * Jumps to the given line. - * - * @param line the line to jump to - */ - private void gotoLine(int line) { - - ITextEditor editor= getTextEditor(); - - IDocumentProvider provider= editor.getDocumentProvider(); - IDocument document= provider.getDocument(editor.getEditorInput()); - try { - - int start= document.getLineOffset(line); - editor.selectAndReveal(start, 0); - - IWorkbenchPage page= editor.getSite().getPage(); - page.activate(editor); - - } catch (BadLocationException x) { - // ignore - } - } - - /* - * @see Action#run() - */ - public void run() { - try { - - ITextEditor editor= getTextEditor(); - - if (editor == null) - return; - - IDocumentProvider docProvider= editor.getDocumentProvider(); - if (docProvider == null) - return; - - IDocument document= docProvider.getDocument(editor.getEditorInput()); - if (document == null) - return; - - fLastLine= document.getLineOfOffset(document.getLength()) + 1; - - String title= fBundle.getString(fPrefix + "dialog.title"); //$NON-NLS-1$ - String message= MessageFormat.format(fBundle.getString(fPrefix + "dialog.message"), new Object[] {new Integer(fLastLine)}); //$NON-NLS-1$ - - GotoLineDialog d= new GotoLineDialog(editor.getSite().getShell(), title, message, "", new NumberValidator()); //$NON-NLS-1$ - if (d.open() == d.OK) { - try { - int line= Integer.parseInt(d.getValue()); - gotoLine(line - 1); - } catch (NumberFormatException x) { - } - } - - } catch (BadLocationException x) { - } - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java deleted file mode 100644 index 2e5ba97b671..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IAbstractTextEditorHelpContextIds.java +++ /dev/null @@ -1,233 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.ui.PlatformUI; - - -/** - * Help context ids for the text editor. - * <p> - * This interface contains constants only; it is not intended to be implemented. - * </p> - */ -public interface IAbstractTextEditorHelpContextIds { - - /** - * The string with which all other defined ids are prefixed to construct help context ids. - * Value: <code>"org.eclipse.ui."</code> - */ - public static final String PREFIX= PlatformUI.PLUGIN_ID + "."; //$NON-NLS-1$ - - /** - * The string which is appended to action ids to construct help context ids. - * Value: <code>"_action_context"</code> - */ - public static final String ACTION_POSTFIX= "_action_context"; //$NON-NLS-1$ - - - - - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.undo_action_context"</code> - */ - public static final String UNDO_ACTION= PREFIX + ITextEditorActionConstants.UNDO + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.redo_action_context"</code> - */ - public static final String REDO_ACTION= PREFIX + ITextEditorActionConstants.REDO + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.cut_action_context"</code> - */ - public static final String CUT_ACTION= PREFIX + ITextEditorActionConstants.CUT + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.copy_action_context"</code> - */ - public static final String COPY_ACTION= PREFIX + ITextEditorActionConstants.COPY + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.paste_action_context"</code> - */ - public static final String PASTE_ACTION= PREFIX + ITextEditorActionConstants.PASTE + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.delete_action_context"</code> - */ - public static final String DELETE_ACTION= PREFIX + ITextEditorActionConstants.DELETE + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.DeleteLine_action_context"</code> - * @since 2.0 - */ - public static final String DELETE_LINE_ACTION= PREFIX + ITextEditorActionConstants.DELETE_LINE + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.DeleteLineToBeginning_action_context"</code> - * @since 2.0 - */ - public static final String DELETE_LINE_TO_BEGINNING_ACTION= PREFIX + ITextEditorActionConstants.DELETE_LINE_TO_BEGINNING + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.DeleteLineToEnd_action_context"</code> - * @since 2.0 - */ - public static final String DELETE_LINE_TO_END_ACTION= PREFIX + ITextEditorActionConstants.DELETE_LINE_TO_END + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.SetMark_action_context"</code> - * @since 2.0 - */ - public static final String SET_MARK_ACTION= PREFIX + ITextEditorActionConstants.SET_MARK + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.ClearMark_action_context"</code> - * @since 2.0 - */ - public static final String CLEAR_MARK_ACTION= PREFIX + ITextEditorActionConstants.CLEAR_MARK + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.SwapMark_action_context"</code> - * @since 2.0 - */ - public static final String SWAP_MARK_ACTION= PREFIX + ITextEditorActionConstants.SWAP_MARK + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.selectAll_action_context"</code> - */ - public static final String SELECT_ALL_ACTION= PREFIX + ITextEditorActionConstants.SELECT_ALL + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.ShiftRight_action_context"</code> - */ - public static final String SHIFT_RIGHT_ACTION= PREFIX + ITextEditorActionConstants.SHIFT_RIGHT + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.ShiftLeft_action_context"</code> - */ - public static final String SHIFT_LEFT_ACTION= PREFIX + ITextEditorActionConstants.SHIFT_LEFT + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.find_action_context"</code> - */ - public static final String FIND_ACTION= PREFIX + ITextEditorActionConstants.FIND + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.FindNext_action_context"</code> - * @since 2.0 - */ - public static final String FIND_NEXT_ACTION= PREFIX + ITextEditorActionConstants.FIND_NEXT + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.FindPrevious_action_context"</code> - * @since 2.0 - */ - public static final String FIND_PREVIOUS_ACTION= PREFIX + ITextEditorActionConstants.FIND_PREVIOUS + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.FindIncremental_action_context"</code> - * @since 2.0 - */ - public static final String FIND_INCREMENTAL_ACTION= PREFIX + ITextEditorActionConstants.FIND_INCREMENTAL + ACTION_POSTFIX; - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.FindIncrementalReverse_action_context"</code> - * @since 2.1 - */ - public static final String FIND_INCREMENTAL_REVERSE_ACTION= PREFIX + ITextEditorActionConstants.FIND_INCREMENTAL_REVERSE + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.bookmark_action_context"</code> - */ - public static final String BOOKMARK_ACTION= PREFIX + ITextEditorActionConstants.BOOKMARK + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.addTask_action_context"</code> - */ - public static final String ADD_TASK_ACTION= PREFIX + ITextEditorActionConstants.ADD_TASK + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.save_action_context"</code> - */ - public static final String SAVE_ACTION= PREFIX + ITextEditorActionConstants.SAVE + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.revert_action_context"</code> - */ - public static final String REVERT_TO_SAVED_ACTION= PREFIX + ITextEditorActionConstants.REVERT_TO_SAVED + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.GotoLine_action_context"</code> - */ - public static final String GOTO_LINE_ACTION= PREFIX + ITextEditorActionConstants.GOTO_LINE + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.print_action_context"</code> - */ - public static final String PRINT_ACTION= PREFIX + ITextEditorActionConstants.PRINT + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.ConvertLineDelimitersToWindows_action_context"</code> - * @since 2.0 - */ - public static final String CONVERT_LINE_DELIMITERS_TO_WINDOWS= PREFIX + ITextEditorActionConstants.CONVERT_LINE_DELIMITERS_TO_WINDOWS + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.ConvertLineDelimitersToUNIX_action_context"</code> - * @since 2.0 - */ - public static final String CONVERT_LINE_DELIMITERS_TO_UNIX= PREFIX + ITextEditorActionConstants.CONVERT_LINE_DELIMITERS_TO_UNIX + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.ConvertLineDelimitersToMAC_action_context"</code> - * @since 2.0 - */ - public static final String CONVERT_LINE_DELIMITERS_TO_MAC= PREFIX + ITextEditorActionConstants.CONVERT_LINE_DELIMITERS_TO_MAC + ACTION_POSTFIX; - - /** - * Help context id for the action. - * Value: <code>"org.eclipse.ui.find_replace_dialog_context"</code> - */ - public static final String FIND_REPLACE_DIALOG= PREFIX + "find_replace_dialog_context"; //$NON-NLS-1$ -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProvider.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProvider.java deleted file mode 100644 index aac92d96a0c..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProvider.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.source.IAnnotationModel; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - - - -/** - * A document provider maps between domain elements and documents. - * A document provider has the following responsibilities: - * <ul> - * <li> create an annotation model of a domain model element - * <li> create and manage a textual representation, i.e., a document, of a domain model element - * <li> create and save the content of domain model elements based on given documents - * <li> update the documents this document provider manages for domain model elements - * to changes directly applied to those domain model elements - * <li> notify all element state listeners about changes directly applied to domain model - * elements this document provider manages a document for, i.e. the document - * provider must know which changes of a domain model element are to be interpreted - * as element moves, deletes, etc. - * </ul> - * Text editors use document providers to bridge the gap between their input elements and the - * documents they work on. A single document provider may be shared between multiple editors; - * the methods take the editors' input elements as a parameter.<p> - * This interface may be implemented by clients; or subclass the standard - * abstract base class <code>AbstractDocumentProvider</code>. - * - * @see IDocument - * @see AbstractDocumentProvider - */ -public interface IDocumentProvider { - - /** - * Connects the given element to this document provider. This tells the provider - * that caller of this method is interested to work with the document provided for - * the given domain model element. By counting the invokations of this method and - * <code>disconnect(Object)</code> this provider can assume to know the - * correct number of clients working with the document provided for that - * domain model element. <p> - * The given element must not be <code>null</code>. - * - * @param element the element - * @exception CoreException if the textual representation or the annotation model - * of the element could not be created - */ - void connect(Object element) throws CoreException; - - /** - * Disconnects the given element from this document provider. This tells the provider - * that the caller of this method is no longer interested in working with the document - * provided for the given domain model element. By counting the invokations of - * <code>connect(Object)</code> and of this method this provider can assume to - * know the correct number of clients working with the document provided for that - * domain model element. <p> - * The given element must not be <code>null</code>. - * - * @param element the element - */ - void disconnect(Object element); - - /** - * Returns the document for the given element. Usually the document contains - * a textual presentation of the content of the element, or is the element itself. - * - * @param element the element, or <code>null</code> - * @return the document, or <code>null</code> if none - */ - IDocument getDocument(Object element); - - /** - * Resets the given element's document to its last saved state. - * Element state listeners are notified both before (<code>elementContentAboutToBeReplaced</code>) - * and after (<code>elementContentReplaced</code>) the content is changed. - * - * @param element the element, or <code>null</code> - */ - void resetDocument(Object element) throws CoreException; - - /** - * Saves the given document provided for the given element. - * - * @param monitor a progress monitor to report progress and request cancelation - * @param element the element, or <code>null</code> - * @param document the document - * @param overwrite indicates whether overwrite should be performed - * while saving the given element if necessary - * @exception CoreException if document could not be stored to the given element - */ - void saveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException; - - /** - * Returns the modification stamp of the given element. - * - * @param element the element - * @return the modification stamp of the given element - */ - long getModificationStamp(Object element); - - /** - * Returns the time stamp of the last synchronization of - * the given element and it's provided document. - * - * @param element the element - * @return the sysnchronization stamp of the given element - */ - long getSynchronizationStamp(Object element); - - /** - * Returns whether the given element has been deleted. - * - * @param element the element - * @return <code>true</code> if the element has been deleted - */ - boolean isDeleted(Object element); - - /** - * Returns whether the document provided for the given element must be saved. - * - * @param element the element, or <code>null</code> - * @return <code>true</code> if the document must be saved, and - * <code>false</code> otherwise (including the element is <code>null</code>) - */ - boolean mustSaveDocument(Object element); - - /** - * Returns whether the document provided for the given element differs from - * its original state which would required that it be saved. - * - * @param element the element, or <code>null</code> - * @return <code>true</code> if the document can be saved, and - * <code>false</code> otherwise (including the element is <code>null</code>) - */ - boolean canSaveDocument(Object element); - - /** - * Returns the annotation model for the given element. - * - * @param element the element, or <code>null</code> - * @return the annotation model, or <code>null</code> if none - */ - IAnnotationModel getAnnotationModel(Object element); - - /** - * Informs this document provider about upcoming changes of the given element. - * The changes might cause change notifications specific for the type of the given element. - * If this provider manages a document for the given element, the document provider - * must not change the document because of the notifications received after <code> - * aboutToChange</code> has been and before <code>changed</code> is called. In this case, - * it is assumed that the document is already up to date, e.g., a save operation is a - * typical case. <p> - * The concrete nature of the change notification depends on the concrete type of the - * given element. If the element is, e.g., an <code>IResource</code> the notification - * is a resource delta. - * - * @param element the element, or <code>null</code> - */ - void aboutToChange(Object element); - - /** - * Informs this document provider that the given element has been changed. - * All notifications have been sent out. If this provider manages a document - * for the given element, the document provider must from now on change the - * document on the receipt of change notifications. The concrete nature of the change - * notification depends on the concrete type of the given element. If the element is, - * e.g., an <code>IResource</code> the notification is a resource delta. - * - * @param element the element, or <code>null</code> - */ - void changed(Object element); - - /** - * Adds the given element state listener to this document provider. - * Has no effect if an identical listener is already registered. - * - * @param listener the listener - */ - void addElementStateListener(IElementStateListener listener); - - /** - * Removes the given element state listener from this document provider. - * Has no affect if an identical listener is not registered. - * - * @param listener the listener - */ - void removeElementStateListener(IElementStateListener listener); -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProviderExtension.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProviderExtension.java deleted file mode 100644 index 27d14c601a7..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IDocumentProviderExtension.java +++ /dev/null @@ -1,114 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; - - -/** - * Extension interface for <code>IDocumentProvider</code>. It adds the following - * functions: - * <ul> - * <li> dealing with immutable domain elements - * <li> state validation - * <li> persistent status of domain element operations - * <li> extended synchronization support - * </ul> - * @since 2.0 - */ -public interface IDocumentProviderExtension { - - /** - * Returns whether the document provider thinks that the given element is read-only. - * If this method returns <code>true</code>, <code>saveDocument</code> could fail. - * This method does not say anything about the document constructed from the given - * element. If the given element is not connected to this document provider, the return - * value is undefined. Document providers are allowed to use a cache to answer this - * question, i.e. there can be a difference between the "real" state of the element and - * the return value. - * - * @param element the element - * @return <code>true</code> if the given element is read-only, <code>false</code> otherwise - */ - boolean isReadOnly(Object element); - - /** - * Returns whether the document provider thinks that the given element can persistently be modified. - * This is orthogonal to <code>isReadOnly</code> as read-only elements may be modifiable and - * writable elements may not be modifiable. If the given element is not connected to this document - * provider, the result is undefined. Document providers are allowed to use a cache to answer this - * question, i.e. there can be a difference between the "real" state of the element and the return - * value. - * - * @param element the element - * @return <code>true</code> if the given element is modifiable, <code>false</code> otherwise - */ - boolean isModifiable(Object element); - - /** - * Validates the state of the given element. This method may change the "real" state of the - * element. If using, it also updates the internal caches, so that this method may also change - * the results returned by <code>isReadOnly</code> and <code>isModifiable</code>. If the - * given element is not connected to this document provider, the effect is undefined. - * - * @param element the element - * @param computationContext the context in which the computation is performed, e.g., a SWT shell - * @exception CoreException if validating fails - */ - void validateState(Object element, Object computationContext) throws CoreException; - - /** - * Returns whether the state of the given element has been validated. - * - * @param element the element - */ - boolean isStateValidated(Object element); - - /** - * Updates the state cache for the given element. This method may change the result returned - * by <code>isReadOnly</code> and <code>isModifiable</code>. If the given element is not - * connected to this document provider, the effect is undefined. - * - * @param element the element - * @exception CoreException if validating fails - */ - void updateStateCache(Object element) throws CoreException; - - /** - * Marks the document managed for the given element as saveable. I.e. - * <code>canBeSaved(element)</code> will return <code>true</code> - * afterwards. - * - * @param element the element - */ - void setCanSaveDocument(Object element); - - /** - * Returns the status of the given element. - * - * @param element the element - * @return the status of the given element - */ - IStatus getStatus(Object element); - - /** - * Synchronizes the document provided for the given element with the - * given element. After that call <code>getSynchronizationTimeStamp</code> - * and <code>getModificationTimeStamp</code> return the same value. - * - * @param element the element - * @exception CoreException if the synchronization could not be performed - */ - void synchronize(Object element) throws CoreException; -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IEditorStatusLine.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IEditorStatusLine.java deleted file mode 100644 index 0c908044b84..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IEditorStatusLine.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.eclipse.ui.texteditor; - -import org.eclipse.swt.graphics.Image; - -/** - * An interface to use the status line of an editor. - * - * @since 2.1 - */ -public interface IEditorStatusLine { - /** - * Sets the image and message to be displayed on the status line. - * <p> - * The error flag indicates that the message is an error message. - * If the error flag is set, a potential non-error message is overridden. - * If the error message is <code>null</code>, the non-error message is displayed. - * </p> - * - * @param error indicates that the message is an error message - * @param message the message to set (may be <code>null</code> to clear the message) - * @param image the image to set (may be <code>null</code> to clear the image) - */ - void setMessage(boolean error, String message, Image image); - -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListener.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListener.java deleted file mode 100644 index cfae2352d92..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListener.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * Interface for parties interested in standardized element changes. These - * changes are: - * <ul> - * <li> dirty state changes - * <li> content replacements - * <li> moves - * <li> deletions - * </ul> - * The notifications sent to the element state listeners inform about those standardized, - * abstract changes. The concrete change applied might differ from the one the listeners - * are notified about, but should be interpreted as the one the listeners receive. - */ -public interface IElementStateListener { - - /** - * Notifies that the dirty state of the given element has changed. - * - * @param element the element - * @param isDirty the new dirty state - */ - void elementDirtyStateChanged(Object element, boolean isDirty); - - /** - * Notifies that the content of the given element is about to be replaced. - * - * @param element the element - */ - void elementContentAboutToBeReplaced(Object element); - - /** - * Notifies that the content of the given element has been replaced. - * - * @param element the element - */ - void elementContentReplaced(Object element); - - /** - * Notifies that the given element has been deleted. - * - * @param element the element - */ - void elementDeleted(Object element); - - /** - * Notifies that the element has moved. If <code>movedElement</code> - * is <code>null</code> it is similar to <code>elementDeleted(originalElement)</code>. - * - * @param originalElement the element before the move - * @param movedElement the element after the move - */ - void elementMoved(Object originalElement, Object movedElement); -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListenerExtension.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListenerExtension.java deleted file mode 100644 index fea0399429f..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IElementStateListenerExtension.java +++ /dev/null @@ -1,47 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - -/** - * Extension interface for <code>IElementStateListener</code>. - * It adds - * <ul> - * <li> state validation notification - * <li>a notion of session, i.e. a notification about an upcoming element change and error handling. - * </ul> - * @since 2.0 - */ -public interface IElementStateListenerExtension { - - /** - * Notifies that the state validation of the given element has changed. - * - * @param element the element - * @param isStateValidated the flag indicating whether state validation is done - */ - void elementStateValidationChanged(Object element, boolean isStateValidated); - - /** - * Notifies that the given element is currently being changed. This method may - * be sent from a non-ui thread. - * - * @param element the element - */ - void elementStateChanging(Object element); - - /** - * Notifies that changing the given element has failed. - * - * @param element the element - */ - void elementStateChangeFailed(Object element); -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IMarkerUpdater.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IMarkerUpdater.java deleted file mode 100644 index 55676c36ecf..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IMarkerUpdater.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - -import org.eclipse.core.resources.IMarker; - - -/** - * A marker updater is responsible for saving changes to markers. - * Marker updaters either update markers of a specific types or - * any type. Also they either assume update responsibility for a - * specific set of marker attributes or any marker attribute. - * Marker updater must be registered with an <code>AbstractMarkerAnnotationModel</code>. - */ -public interface IMarkerUpdater { - - /** - * Returns the marker type for which this updater is responsible. If - * the result is <code>null</code>, the updater assumes responsibility - * for any marker type. - * - * @return the marker type or <code>null</code> for any marker type - */ - String getMarkerType(); - - /** - * Returns the attributes for which this updater is responsible. If the - * result is <code>null</code>, the updater assumes responsibility for - * any attributes. - * - * @return the attributes or <code>null</code> for any attribute - */ - String[] getAttribute(); - - /** - * Updates the given marker according to the position of the given document. - * If the given position is <code>null</code>, the marker is assumed to - * carry the correct positional information. If the updater recognizes that - * the marker should be deleted, it returns <code>false</code>. - * - * @param marker the marker to be updated - * @param document the document into which the given position points - * @param position the current position of the marker inside the given document - */ - boolean updateMarker(IMarker marker, IDocument document, Position position); -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IReadOnlyDependent.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IReadOnlyDependent.java deleted file mode 100644 index 3146d7a35d2..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IReadOnlyDependent.java +++ /dev/null @@ -1,37 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v0.5 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v05.html - -Contributors: - IBM Corporation - Initial API and implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - - -/** - * Extension interface for actions. Actions implementing this interface not - * only manage an enable/disable state but also manage a "hypothetical" - * enable state, depending on whether the target they work on is writable - * or read-only. - * @since 2.0 - */ -public interface IReadOnlyDependent { - - /** - * Returns whether the actions would be enabled if its target - * would be enabled given the writable state described by <code>isWritable</code>. - * <code>isEnabled()</code> and <code>isEnabled(boolean)</code> holds the following - * invariants: - * isEnabled() == false, iff isEnabled(true) == false || isEnabled(false) == false - * isEnabled() == true, iff isEnabled(true) == true || isEnabled(false) == true - * - * @param isWritable - * @return the hypothetical enable state of the action - */ - boolean isEnabled(boolean isWritable); -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IStatusField.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IStatusField.java deleted file mode 100644 index 712dc4b4d0b..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IStatusField.java +++ /dev/null @@ -1,39 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.swt.graphics.Image; - - -/** - * Interface of a status field of a text editor. The field that shows up in the - * workbench's status line if the contributing editor is active. - * @since 2.0 - */ -public interface IStatusField { - - /** - * Sets the text of this status field. - * - * @param text the text shown in the status field - */ - void setText(String text); - - /** - * Sets the image of this status field. - * - * @param image the image shown in the status field - */ - void setImage(Image image); -} - diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditor.java deleted file mode 100644 index e4ceb3c3c74..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditor.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.viewers.ISelectionProvider; - -import org.eclipse.ui.IEditorPart; - - -/** - * Interface to a text editor. This interface defines functional extensions to - * <code>IEditorPart</code> as well as the configuration capabilities of a text editor. - * <p> - * Text editors are configured with an <code>IDocumentProvider</code> which - * delivers a textual presentation (<code>IDocument</code>) of the editor's input. - * The editor works on the document and forwards all input element related calls, - * such as <code>save</code>, to the document provider. The provider also delivers - * the input's annotation model which is used to control the editor's vertical ruler. - * </p> - * <p> - * Clients may implement this interface from scratch, but the recommended way is to - * subclass the abstract base class <code>AbstractTextEditor</code>. - * </p> - * - * @see IDocumentProvider - * @see org.eclipse.jface.text.source.IAnnotationModel - */ -public interface ITextEditor extends IEditorPart { - - /** - * Returns this text editor's document provider. - * - * @return the document provider - */ - IDocumentProvider getDocumentProvider(); - - /** - * Closes this text editor after optionally saving changes. - * - * @param save <code>true</code> if unsaved changed should be saved, and - * <code>false</code> if unsaved changed should be discarded - */ - void close(boolean save); - - /** - * Returns whether the text in this text editor can be changed by the user. - * - * @return <code>true</code> if it can be edited, and <code>false</code> - * if it is read-only - */ - boolean isEditable(); - - /** - * Abandons all modifications applied to this text editor's input element's - * textual presentation since the last save operation. - */ - void doRevertToSaved(); - - /** - * Installs the given action under the given action id. - * - * @param actionId the action id - * @param action the action, or <code>null</code> to clear it - * @see #getAction - */ - void setAction(String actionID, IAction action); - - /** - * Returns the action installed under the given action id. - * - * @param actionId the action id - * @return the action, or <code>null</code> if none - * @see #setAction - */ - IAction getAction(String actionId); - - /** - * Sets the given activation code for the specified action. If - * there is an activation code already registered, it is replaced. - * The activation code consists of the same information as - * a <code>KeyEvent</code>. If the activation code is triggered - * and the associated action is enabled, the action is performed - * and the triggering <code>KeyEvent</code> is considered consumed. - * If the action is disabled, the <code>KeyEvent</code> is passed - * on unmodified. Thus, action activation codes and action accelerators - * differ in their model of event consumption. The key code parameter - * can be <code>-1</code> to indicate a wild card. The state mask - * parameter can be SWT.DEFAULT to indicate a wild card - * - * @param actionId the action id - * @param character the activation code character - * @param keyCode the activation code key code or <code>-1</code> for wild card - * @param stateMask the activation code state mask or <code>SWT.DEFAULT</code> for wild card - */ - void setActionActivationCode(String actionId, char activationCharacter, int activationKeyCode, int activationStateMask); - - /** - * Removes any installed activation code for the specified action. - * If no activation code is installed, this method does not have - * any effect. - * - * @param actionId the action id - */ - void removeActionActivationCode(String actionId); - - /** - * Returns whether this text editor is configured to show only the - * highlighted range of the text. - * - * @return <code>true</code> if only the highlighted range is shown, and - * <code>false</code> if this editor shows the entire text of the document - * @see #showHighlightRangeOnly - */ - boolean showsHighlightRangeOnly(); - - /** - * Configures this text editor to show only the highlighted range of the - * text. - * - * @param showHighlightRangeOnly <code>true</code> if only the highlighted - * range is shown, and <code>false</code> if this editor shows the entire - * text of the document - * @see #showsHighlightRangeOnly - */ - void showHighlightRangeOnly(boolean showHighlightRangeOnly); - - /** - * Sets the highlighted range of this text editor to the specified region. - * - * @param offset the offset of the highlighted range - * @param length the length of the highlighted range - * @param moveCursor <code>true</code> if the cursor should be moved to - * the start of the highlighted range, and <code>false</code> to leave - * the cursor unaffected - * @see #getHighlightRange - */ - void setHighlightRange(int offset, int length, boolean moveCursor); - - /** - * Returns the highlighted range of this text editor. - * - * @return the highlighted range - * @see #setHighlightRange - */ - IRegion getHighlightRange(); - - /** - * Resets the highlighted range of this text editor. - */ - void resetHighlightRange(); - - /** - * Returns this text editor's selection provider. Repeated calls to this - * method return the same selection provider. - * - * @return the selection provider - */ - ISelectionProvider getSelectionProvider(); - - /** - * Selects and reveals the specified range in this text editor. - * - * @param offset the offset of the selection - * @param length the length of the selection - */ - void selectAndReveal(int offset, int length); -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java deleted file mode 100644 index 0427ddcbc4c..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java +++ /dev/null @@ -1,235 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.ui.IWorkbenchActionConstants; - - -/** - * Defines the names of those actions which are preregistered with the - * <code>AbstractTextEditor</code>. <code>RULER_DOUBLE_CLICK</code> defines - * the action which is registered as being executed when the editor's - * ruler has been double clicked. This interface extends the set of names - * available from <code>IWorkbenchActionConstants</code>. It also defines the - * names of the menu groups in a text editor's context menu. - */ -public interface ITextEditorActionConstants extends IWorkbenchActionConstants { - - /** - * Context menu group for undo/redo related actions. - * Value: <code>"group.undo"</code> - */ - static final String GROUP_UNDO= "group.undo"; //$NON-NLS-1$ - - /** - * Context menu group for copy/paste related actions. - * Value: <code>"group.copy"</code> - */ - static final String GROUP_COPY= "group.copy"; //$NON-NLS-1$ - - /** - * Context menu group for text manipulation actions. - * Value: <code>"group.edit"</code> - */ - static final String GROUP_EDIT= "group.edit"; //$NON-NLS-1$ - - /** - * Context menu group for print related actions. - * Value: <code>"group.print"</code> - */ - static final String GROUP_PRINT= "group.print"; //$NON-NLS-1$ - - /** - * Context menu group for find/replace related actions. - * Value: <code>"group.find"</code> - */ - static final String GROUP_FIND= "group.find"; //$NON-NLS-1$ - - /** - * Context menu group for save related actions. - * Value: <code>"group.save"</code> - */ - static final String GROUP_SAVE= "group.save"; //$NON-NLS-1$ - - /** - * Context menu group for actions which do not fit in one of the other categories. - * Value: <code>"group.rest"</code> - */ - static final String GROUP_REST= "group.rest"; //$NON-NLS-1$ - - - - /** - * Name of the action for shifting text blocks to the right. - * Value: <code>"ShiftRight"</code> - */ - static final String SHIFT_RIGHT= "ShiftRight"; //$NON-NLS-1$ - - /** - * Name of the action for shifting text blocks to the left. - * Value: <code>"ShiftLeft"</code> - */ - static final String SHIFT_LEFT= "ShiftLeft"; //$NON-NLS-1$ - - /** - * Name of the action for re-establishing the state after the - * most recent save operation. - * Value: <code>"IWorkbenchActionConstants.REVERT"</code> - */ - static final String REVERT_TO_SAVED= REVERT; - - /** - * Name of the action to delete the current line. - * Value: <code>"DeleteLine"</code> - * @since 2.0 - */ - static final String DELETE_LINE= "DeleteLine"; //$NON-NLS-1$ - - /** - * Name of the action to delete line to beginning. - * Value: <code>"DeleteLineToBeginning"</code> - * @since 2.0 - */ - static final String DELETE_LINE_TO_BEGINNING= "DeleteLineToBeginning"; //$NON-NLS-1$ - - /** - * Name of the action to delete line to end. - * Value: <code>"DeleteLineToEnd"</code> - * @since 2.0 - */ - static final String DELETE_LINE_TO_END= "DeleteLineToEnd"; //$NON-NLS-1$ - - /** - * Name of the action to set the mark. - * Value: <code>"SetMark"</code> - * @since 2.0 - */ - static final String SET_MARK= "SetMark"; //$NON-NLS-1$ - - /** - * Name of the action to set the mark. - * Value: <code>"ClearMark"</code> - * @since 2.0 - */ - static final String CLEAR_MARK= "ClearMark"; //$NON-NLS-1$ - - /** - * Name of the action to swap the mark with the cursor position. - * Value: <code>"SwapMark"</code> - * @since 2.0 - */ - static final String SWAP_MARK= "SwapMark"; //$NON-NLS-1$ - - /** - * Name of the action to jump to a certain text line. - * Value: <code>"GotoLine"</code> - */ - static final String GOTO_LINE= "GotoLine"; //$NON-NLS-1$ - - /** - * Name of the action to find next. - * Value: <code>"FindNext"</code> - * @since 2.0 - */ - static final String FIND_NEXT= "FindNext"; //$NON-NLS-1$ - - /** - * Name of the action to find previous. - * Value: <code>"FindPrevious"</code> - * @since 2.0 - */ - static final String FIND_PREVIOUS= "FindPrevious"; //$NON-NLS-1$ - - /** - * Name of the action to incremental find. - * Value: <code>"FindIncremental"</code> - * @since 2.0 - */ - static final String FIND_INCREMENTAL= "FindIncremental"; //$NON-NLS-1$ - /** - * Name of the action to incremental find reverse. - * Value: <code>"FindIncrementalReverse"</code> - * @since 2.1 - */ - static final String FIND_INCREMENTAL_REVERSE= "FindIncrementalReverse"; //$NON-NLS-1$ - - /** - * Name of the action to convert line delimiters to Windows. - * Value: <code>"ConvertLineDelimitersToWindows"</code> - * @since 2.0 - */ - static final String CONVERT_LINE_DELIMITERS_TO_WINDOWS= "ConvertLineDelimitersToWindows"; //$NON-NLS-1$ - - /** - * Name of the action to convert line delimiters to UNIX. - * Value: <code>"ConvertLineDelimitersToUNIX"</code> - * @since 2.0 - */ - static final String CONVERT_LINE_DELIMITERS_TO_UNIX= "ConvertLineDelimitersToUNIX"; //$NON-NLS-1$ - - /** - * Name of the action to convert line delimiters to MAC. - * Value: <code>"ConvertLineDelimitersToMAC"</code> - * @since 2.0 - */ - static final String CONVERT_LINE_DELIMITERS_TO_MAC= "ConvertLineDelimitersToMAC"; //$NON-NLS-1$ - - - - /** - * Name of the ruler action performed when double clicking the editor's vertical ruler. - * Value: <code>"RulerDoubleClick"</code> - */ - static final String RULER_DOUBLE_CLICK= "RulerDoubleClick"; //$NON-NLS-1$ - - /** - * Name of the ruler action performed when clicking the editor's vertical ruler. - * Value: <code>"RulerClick"</code> - * @since 2.0 - */ - static final String RULER_CLICK= "RulerClick"; //$NON-NLS-1$ - - /** - * Name of the ruler action to manage tasks. - * Value: <code>"ManageTasks"</code> - */ - static final String RULER_MANAGE_TASKS= "ManageTasks"; //$NON-NLS-1$ - - /** - * Name of the ruler action to manage bookmarks. - * Value: <code>"ManageBookmarks"</code> - */ - static final String RULER_MANAGE_BOOKMARKS= "ManageBookmarks"; //$NON-NLS-1$ - - - /** - * Status line category "input position". - * Value: <code>"InputPosition"</code> - * @since 2.0 - */ - static final String STATUS_CATEGORY_INPUT_POSITION= "InputPosition"; //$NON-NLS-1$ - - /** - * Status line category "input mode". - * Value: <code>"InputMode"</code> - * @since 2.0 - */ - static final String STATUS_CATEGORY_INPUT_MODE= "InputMode"; //$NON-NLS-1$ - - /** - * Status line category "element state". - * Value: <code>"ElementState"</code> - * @since 2.0 - */ - static final String STATUS_CATEGORY_ELEMENT_STATE= "ElementState"; //$NON-NLS-1$ -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java deleted file mode 100644 index 933c0975b94..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java +++ /dev/null @@ -1,310 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - -/** - * Defines the definitions ids for the text editor actions. These actions are - * navigation, selection, and modification actions. - * @since 2.0 - */ -public interface ITextEditorActionDefinitionIds extends IWorkbenchActionDefinitionIds { - - // edit - - /** - * Action definition id of the edit delete line action. - * Value: <code>"org.eclipse.ui.edit.text.delete.line"</code> - */ - public static final String DELETE_LINE= "org.eclipse.ui.edit.text.delete.line"; //$NON-NLS-1$ - - /** - * Action definition id of the edit delete line to beginning action. - * Value: <code>"org.eclipse.ui.edit.text.delete.line.to.beginning"</code> - */ - public static final String DELETE_LINE_TO_BEGINNING= "org.eclipse.ui.edit.text.delete.line.to.beginning"; //$NON-NLS-1$ - - /** - * Action definition id of the edit delete line to end action. - * Value: <code>"org.eclipse.ui.edit.text.delete.line.to.end"</code> - */ - public static final String DELETE_LINE_TO_END= "org.eclipse.ui.edit.text.delete.line.to.end"; //$NON-NLS-1$ - - /** - * Action definition id of the edit set mark action. - * Value: <code>"org.eclipse.ui.edit.text.set.mark"</code> - */ - public static final String SET_MARK= "org.eclipse.ui.edit.text.set.mark"; //$NON-NLS-1$ - - /** - * Action definition id of the edit clear mark action. - * Value: <code>"org.eclipse.ui.edit.text.clear.mark"</code> - */ - public static final String CLEAR_MARK= "org.eclipse.ui.edit.text.clear.mark"; //$NON-NLS-1$ - - /** - * Action definition id of the edit swap mark action. - * Value: <code>"org.eclipse.ui.edit.text.swap.mark"</code> - */ - public static final String SWAP_MARK= "org.eclipse.ui.edit.text.swap.mark"; //$NON-NLS-1$ - - - // navigation - - /** - * Action definition id of the navigate goto previous line action. - * Value: <code>"org.eclipse.ui.edit.text.goto.lineUp"</code> - */ - public static final String LINE_UP= "org.eclipse.ui.edit.text.goto.lineUp"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto next line action. - * Value: <code>"org.eclipse.ui.edit.text.goto.lineDown"</code> - */ - public static final String LINE_DOWN= "org.eclipse.ui.edit.text.goto.lineDown"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto line start action. - * Value: <code>"org.eclipse.ui.edit.text.goto.lineStart"</code> - */ - public static final String LINE_START= "org.eclipse.ui.edit.text.goto.lineStart"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto line end action. - * Value: <code>"org.eclipse.ui.edit.text.goto.lineEnd"</code> - */ - public static final String LINE_END= "org.eclipse.ui.edit.text.goto.lineEnd"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto line action. - * Value: <code>"org.eclipse.ui.edit.text.goto.line"</code> - */ - public static final String LINE_GOTO= "org.eclipse.ui.edit.text.goto.line"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto previous column action. - * Value: <code>"org.eclipse.ui.edit.text.goto.columnPrevious"</code> - */ - public static final String COLUMN_PREVIOUS= "org.eclipse.ui.edit.text.goto.columnPrevious"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto next column action. - * Value: <code>"org.eclipse.ui.edit.text.goto.columnNext"</code> - */ - public static final String COLUMN_NEXT= "org.eclipse.ui.edit.text.goto.columnNext"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto previous page action. - * Value: <code>"org.eclipse.ui.edit.text.goto.pageUp"</code> - */ - public static final String PAGE_UP= "org.eclipse.ui.edit.text.goto.pageUp"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto next page action. - * Value: <code>"org.eclipse.ui.edit.text.goto.pageDown"</code> - */ - public static final String PAGE_DOWN= "org.eclipse.ui.edit.text.goto.pageDown"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto previous word action. - * Value: <code>"org.eclipse.ui.edit.text.goto.wordPrevious"</code> - */ - public static final String WORD_PREVIOUS= "org.eclipse.ui.edit.text.goto.wordPrevious"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto next word action. - * Value: <code>"org.eclipse.ui.edit.text.goto.wordNext"</code> - */ - public static final String WORD_NEXT= "org.eclipse.ui.edit.text.goto.wordNext"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto text start action. - * Value: <code>"org.eclipse.ui.edit.text.goto.textStart"</code> - */ - public static final String TEXT_START= "org.eclipse.ui.edit.text.goto.textStart"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto text end action. - * Value: <code>"org.eclipse.ui.edit.text.goto.textEnd"</code> - */ - public static final String TEXT_END= "org.eclipse.ui.edit.text.goto.textEnd"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto start of window action. - * Value: <code>"org.eclipse.ui.edit.text.goto.windowStart"</code> - */ - public static final String WINDOW_START= "org.eclipse.ui.edit.text.goto.windowStart"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate goto end of window action. - * Value: <code>"org.eclipse.ui.edit.text.goto.windowEnd"</code> - */ - public static final String WINDOW_END= "org.eclipse.ui.edit.text.goto.windowEnd"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate scroll line up action. - * Value: <code>"org.eclipse.ui.edit.text.scroll.lineUp"</code> - */ - public static final String SCROLL_LINE_UP= "org.eclipse.ui.edit.text.scroll.lineUp"; //$NON-NLS-1$ - - /** - * Action definition id of the navigate scroll line down action. - * Value: <code>"org.eclipse.ui.edit.text.scroll.lineDown"</code> - */ - public static final String SCROLL_LINE_DOWN= "org.eclipse.ui.edit.text.scroll.lineDown"; //$NON-NLS-1$ - - - // selection - - /** - * Action definition id of the select line up action. - * Value: <code>"org.eclipse.ui.edit.text.select.lineUp"</code> - */ - public static final String SELECT_LINE_UP= "org.eclipse.ui.edit.text.select.lineUp"; //$NON-NLS-1$ - - /** - * Action definition id of the select line down action. - * Value: <code>"org.eclipse.ui.edit.text.select.lineDown"</code> - */ - public static final String SELECT_LINE_DOWN= "org.eclipse.ui.edit.text.select.lineDown"; //$NON-NLS-1$ - - /** - * Action definition id of the select line start action. - * Value: <code>"org.eclipse.ui.edit.text.select.lineStart"</code> - */ - public static final String SELECT_LINE_START= "org.eclipse.ui.edit.text.select.lineStart"; //$NON-NLS-1$ - - /** - * Action definition id of the select line end action. - * Value: <code>"org.eclipse.ui.edit.text.select.lineEnd"</code> - */ - public static final String SELECT_LINE_END= "org.eclipse.ui.edit.text.select.lineEnd"; //$NON-NLS-1$ - - /** - * Action definition id of the select previous column action. - * Value: <code>"org.eclipse.ui.edit.text.select.columnPrevious"</code> - */ - public static final String SELECT_COLUMN_PREVIOUS= "org.eclipse.ui.edit.text.select.columnPrevious"; //$NON-NLS-1$ - - /** - * Action definition id of the select next column action. - * Value: <code>"org.eclipse.ui.edit.text.select.columnNext"</code> - */ - public static final String SELECT_COLUMN_NEXT= "org.eclipse.ui.edit.text.select.columnNext"; //$NON-NLS-1$ - - /** - * Action definition id of the select page up action. - * Value: <code>"org.eclipse.ui.edit.text.select.pageUp"</code> - */ - public static final String SELECT_PAGE_UP= "org.eclipse.ui.edit.text.select.pageUp"; //$NON-NLS-1$ - - /** - * Action definition id of the select page down action. - * Value: <code>"org.eclipse.ui.edit.text.select.pageDown"</code> - */ - public static final String SELECT_PAGE_DOWN= "org.eclipse.ui.edit.text.select.pageDown"; //$NON-NLS-1$ - - /** - * Action definition id of the select previous word action. - * Value: <code>"org.eclipse.ui.edit.text.select.wordPrevious"</code> - */ - public static final String SELECT_WORD_PREVIOUS= "org.eclipse.ui.edit.text.select.wordPrevious"; //$NON-NLS-1$ - - /** - * Action definition id of the select next word action. - * Value: <code>"org.eclipse.ui.edit.text.select.wordNext"</code> - */ - public static final String SELECT_WORD_NEXT= "org.eclipse.ui.edit.text.select.wordNext"; //$NON-NLS-1$ - - /** - * Action definition id of the select text start action. - * Value: <code>"org.eclipse.ui.edit.text.select.textStart"</code> - */ - public static final String SELECT_TEXT_START= "org.eclipse.ui.edit.text.select.textStart"; //$NON-NLS-1$ - - /** - * Action definition id of the select text end action. - * Value: <code>"org.eclipse.ui.edit.text.select.textEnd"</code> - */ - public static final String SELECT_TEXT_END= "org.eclipse.ui.edit.text.select.textEnd"; //$NON-NLS-1$ - - /** - * Action definition id of the select window start action. - * Value: <code>"org.eclipse.ui.edit.text.select.windowStart"</code> - */ - public static final String SELECT_WINDOW_START= "org.eclipse.ui.edit.text.select.windowStart"; //$NON-NLS-1$ - - /** - * Action definition id of the select window end action. - * Value: <code>"org.eclipse.ui.edit.text.select.windowEnd"</code> - */ - public static final String SELECT_WINDOW_END= "org.eclipse.ui.edit.text.select.windowEnd"; //$NON-NLS-1$ - - - // modification - - /** - * Action definition id of the edit delet previous character action. - * Value: <code>"org.eclipse.ui.edit.text.deletePrevious"</code> - */ - public static final String DELETE_PREVIOUS= "org.eclipse.ui.edit.text.deletePrevious"; //$NON-NLS-1$ - - /** - * Action definition id of the edit delete next character action. - * Value: <code>"org.eclipse.ui.edit.text.deleteNext"</code> - */ - public static final String DELETE_NEXT= "org.eclipse.ui.edit.text.deleteNext"; //$NON-NLS-1$ - - /** - * Action definition id of the edit shift right action. - * Value: <code>"org.eclipse.ui.edit.text.shiftRight"</code> - */ - public static final String SHIFT_RIGHT= "org.eclipse.ui.edit.text.shiftRight"; //$NON-NLS-1$ - - /** - * Action definition id of the edit shift left action. - * Value: <code>"org.eclipse.ui.edit.text.shiftLeft"</code> - */ - public static final String SHIFT_LEFT= "org.eclipse.ui.edit.text.shiftLeft"; //$NON-NLS-1$ - - /** - * Action definition id of the edit convert to window's line delimiter action. - * Value: <code>"org.eclipse.ui.edit.text.convert.lineDelimiters.toWindows"</code> - */ - public static final String CONVERT_LINE_DELIMITERS_TO_WINDOWS= "org.eclipse.ui.edit.text.convert.lineDelimiters.toWindows"; //$NON-NLS-1$ - - /** - * Action definition id of the edit convert to unix' line delimiter action. - * Value: <code>"org.eclipse.ui.edit.text.convert.lineDelimiters.toUNIX"</code> - */ - public static final String CONVERT_LINE_DELIMITERS_TO_UNIX= "org.eclipse.ui.edit.text.convert.lineDelimiters.toUNIX"; //$NON-NLS-1$ - - /** - * Action definition id of the edit convert to mac' line delimiter action. - * Value: <code>"org.eclipse.ui.edit.text.convert.lineDelimiters.toMac"</code> - */ - public static final String CONVERT_LINE_DELIMITERS_TO_MAC= "org.eclipse.ui.edit.text.convert.lineDelimiters.toMac"; //$NON-NLS-1$ - - - // miscellaneous - - /** - * Action definition id of the toggle input mode action. - * Value: <code>"org.eclipse.ui.edit.text.toggleOverwrite"</code> - */ - public static final String TOGGLE_OVERWRITE= "org.eclipse.ui.edit.text.toggleOverwrite"; //$NON-NLS-1$ - - /** - * Action definition id of the show ruler context menu action. - * Value: <code>"org.eclipse.ui.edit.text.showRulerContextMenu"</code> - */ - public static final String SHOW_RULER_CONTEXT_MENU= "org.eclipse.ui.edit.text.showRulerContextMenu"; //$NON-NLS-1$ -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorExtension.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorExtension.java deleted file mode 100644 index bce3995c399..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorExtension.java +++ /dev/null @@ -1,64 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.jface.action.IMenuListener; - - -/** - * Extension interface for <code>ITextEditor</code>. Adds the following functions: - * <ul> - * <li> status fields - * <li> read-only state of the editor's input - * <li> ruler context menu listeners. - * </ul> - * - * @since 2.0 - */ -public interface ITextEditorExtension { - - /** - * Informs the editor which status field is to be used when posting status - * information in the given category. - * - * @param field the status field to be used - * @param category the status information category - * @see ITextEditorActionConstants - */ - void setStatusField(IStatusField field, String category); - - /** - * Returns whether the editor's input is read-only. The semantics of - * this method is orthogonal to <code>isEditable</code> as it talks about the - * editor input, i.e. the domain element, and <b>not</b> about the editor - * document. - * - * @return <code>true</code> if the editor input is read-only - */ - boolean isEditorInputReadOnly(); - - /** - * Adds a ruler context menu listener to the editor. - * - * @param listener the listener - */ - void addRulerContextMenuListener(IMenuListener listener); - - /** - * Removes a ruler context menu listener from the editor. - * - * @param listener the listener - */ - void removeRulerContextMenuListener(IMenuListener listener); -} - diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IUpdate.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IUpdate.java deleted file mode 100644 index cda92839ce6..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IUpdate.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Indicates the support of an update method. - */ -public interface IUpdate { - - /** - * Requests that this object update itself. - */ - void update(); -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IWorkbenchActionDefinitionIds.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IWorkbenchActionDefinitionIds.java deleted file mode 100644 index c4b1ee4536b..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IWorkbenchActionDefinitionIds.java +++ /dev/null @@ -1,131 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -/** - * Defines the definitions ids for workbench actions. - * @since 2.0 - */ -public interface IWorkbenchActionDefinitionIds { - - // workbench file actions - - /** - * Action definition id of the file print action. - * Value: <code>"org.eclipse.ui.file.print"</code> - */ - public static final String PRINT= "org.eclipse.ui.file.print"; //$NON-NLS-1$ - - /** - * Action definition id of the file save action. - * Value: <code>"org.eclipse.file.save"</code> - */ - public static final String SAVE= "org.eclipse.file.save"; //$NON-NLS-1$ - - /** - * Action definition id of the file revert action. - * Value: <code>"org.eclipse.ui.edit.revertToSaved"</code> - */ - public static final String REVERT_TO_SAVED= "org.eclipse.ui.edit.revertToSaved"; //$NON-NLS-1$ - - - - // workbench edit actions - - /** - * Action definition id of the edit cut action. - * Value: <code>"org.eclipse.ui.edit.cut"</code> - */ - public static final String CUT= "org.eclipse.ui.edit.cut"; //$NON-NLS-1$ - - /** - * Action definition id of the edit copy action. - * Value: <code>"org.eclipse.ui.edit.copy"</code> - */ - public static final String COPY= "org.eclipse.ui.edit.copy"; //$NON-NLS-1$ - - /** - * Action definition id of the edit past action. - * Value: <code>"org.eclipse.ui.edit.paste"</code> - */ - public static final String PASTE= "org.eclipse.ui.edit.paste"; //$NON-NLS-1$ - - /** - * Action definition id of the edit undo action. - * Value: <code>"org.eclipse.ui.edit.undo"</code> - */ - public static final String UNDO= "org.eclipse.ui.edit.undo"; //$NON-NLS-1$ - - /** - * Action definition id of the edit redo action. - * Value: <code>"org.eclipse.ui.edit.redo"</code> - */ - public static final String REDO= "org.eclipse.ui.edit.redo"; //$NON-NLS-1$ - - /** - * Action definition id of the edit delete action. - * Value: <code>"org.eclipse.ui.edit.delete"</code> - */ - public static final String DELETE= "org.eclipse.ui.edit.delete"; //$NON-NLS-1$ - - /** - * Action definition id of the edit select all action. - * Value: <code>"org.eclipse.ui.edit.selectAll"</code> - */ - public static final String SELECT_ALL= "org.eclipse.ui.edit.selectAll"; //$NON-NLS-1$ - - /** - * Action definition id of the edit find/replace action. - * Value: <code>"org.eclipse.ui.edit.findReplace"</code> - */ - public static final String FIND_REPLACE= "org.eclipse.ui.edit.findReplace"; //$NON-NLS-1$ - - /** - * Action definition id of the edit add bookmark action. - * Value: <code>"org.eclipse.ui.edit.addBookmark"</code> - */ - public static final String ADD_BOOKMARK= "org.eclipse.ui.edit.addBookmark"; //$NON-NLS-1$ - - /** - * Action definition id of the edit add task action. - * Value: <code>"org.eclipse.ui.edit.addTask"</code> - */ - public static final String ADD_TASK= "org.eclipse.ui.edit.addTask"; //$NON-NLS-1$ - - - // future workbench edit actions - - /** - * Action definition id of the edit find next action. - * Value: <code>"org.eclipse.ui.edit.findNext"</code> - */ - public static final String FIND_NEXT= "org.eclipse.ui.edit.findNext"; //$NON-NLS-1$ - /** - * Action definition id of the edit find previous action. - * Value: <code>"org.eclipse.ui.edit.findPrevious"</code> - */ - public static final String FIND_PREVIOUS= "org.eclipse.ui.edit.findPrevious"; //$NON-NLS-1$ - /** - * Action definition id of the edit incremental find action. - * Value: <code>"org.eclipse.ui.edit.findIncremental"</code> - */ - public static final String FIND_INCREMENTAL= "org.eclipse.ui.edit.findIncremental"; //$NON-NLS-1$ - /** - * Action definition id of the edit incremental find reverse action. - * Value: <code>"org.eclipse.ui.edit.findIncrementalReverse"</code> - * - * @since 2.1 - */ - public static final String FIND_INCREMENTAL_REVERSE= "org.eclipse.ui.edit.findIncrementalReverse"; //$NON-NLS-1$ -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindAction.java deleted file mode 100644 index 88c5d8fbcad..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindAction.java +++ /dev/null @@ -1,114 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.IFindReplaceTarget; -import org.eclipse.jface.text.IFindReplaceTargetExtension; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; - - -/** - * An action which enters the incremental find mode a la emacs. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - * @since 2.0 - */ -public class IncrementalFindAction extends ResourceAction implements IUpdate { - - /** The action's target */ - private IFindReplaceTarget fTarget; - /** The part the action is bound to */ - private IWorkbenchPart fWorkbenchPart; - /** The workbench window */ - private IWorkbenchWindow fWorkbenchWindow; - /** The direction to run the incremental find */ - private boolean fForward; - - /** - * Creates a new incremental find action for the given text editor. - * The action configures its visual representation from the given - * resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @param forward <code>true</code> if the search direction is forward - * @see ResourceAction#ResourceAction - */ - public IncrementalFindAction(ResourceBundle bundle, String prefix, IWorkbenchPart workbenchPart, boolean forward) { - super(bundle, prefix); - fWorkbenchPart= workbenchPart; - fForward= forward; - update(); - } - - /** - * Creates a new incremental find action for the given text editor. - * The action configures its visual representation from the given - * resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param workbenchWindow the workbench window - * @param forward <code>true</code> if the search direction is forward - * @see ResourceAction#ResourceAction - * - * @deprecated use FindReplaceAction(ResourceBundle, String, IWorkbenchPart, boolean) instead - */ - public IncrementalFindAction(ResourceBundle bundle, String prefix, IWorkbenchWindow workbenchWindow, boolean forward) { - super(bundle, prefix); - fWorkbenchWindow= workbenchWindow; - fForward= forward; - update(); - } - - /* - * @see IAction#run - */ - public void run() { - - if (fTarget == null) - return; - - if (fTarget instanceof IncrementalFindTarget) - ((IncrementalFindTarget) fTarget).setDirection(fForward); - - if (fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).beginSession(); - } - - /* - * @see IUpdate#update() - */ - public void update() { - - if (fWorkbenchPart == null && fWorkbenchWindow != null) - fWorkbenchPart= fWorkbenchWindow.getPartService().getActivePart(); - - if (fWorkbenchPart != null) - fTarget= (IFindReplaceTarget) fWorkbenchPart.getAdapter(IncrementalFindTarget.class); - else - fTarget= null; - - setEnabled(fTarget != null && fTarget.canPerformFind()); - } - -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindTarget.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindTarget.java deleted file mode 100644 index 36e1960c44f..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/IncrementalFindTarget.java +++ /dev/null @@ -1,641 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - -import java.text.MessageFormat; -import java.util.Stack; - -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.text.*; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.custom.VerifyKeyListener; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Point; - -/** - * An incremental find target. Replace is always disabled. - * @since 2.0 - */ -class IncrementalFindTarget implements IFindReplaceTarget, IFindReplaceTargetExtension, VerifyKeyListener, MouseListener, FocusListener, ISelectionChangedListener, ITextListener { - - /** The string representing rendered tab */ - private final static String TAB= EditorMessages.getString("Editor.FindIncremental.render.tab"); //$NON-NLS-1$ - private final static String REVERSE= EditorMessages.getString("Editor.FindIncremental.reverse"); //$NON-NLS-1$ - private final static String WRAPPED= EditorMessages.getString("Editor.FindIncremental.wrapped"); //$NON-NLS-1$ - - /** The text viewer to operate on */ - private final ITextViewer fTextViewer; - /** The status line manager for output */ - private final IStatusLineManager fStatusLine; - /** The find replace target to delegate find requests */ - private final IFindReplaceTarget fTarget; - - /** The current find string */ - private StringBuffer fFindString= new StringBuffer(); - /** The position of the first upper case character, -1 if none */ - private int fCasePosition; - /** The position in the stack of the first wrap search, -1 if none */ - private int fWrapPosition; - /** The position of the last successful find */ - private int fCurrentIndex; - /** A flag indicating if last find was successful */ - private boolean fFound; - /** A flag indicating if the last search was forward */ - private boolean fForward= true; - /** A flag indicating listeners are installed. */ - private boolean fInstalled; - /** - * A flag indicating that a search is currently active. - * Used to ignore selection callbacks generated by the incremental search itself. - */ - private boolean fSearching; - /** The current find stack */ - private Stack fSessionStack; - /** The previous search string */ - private String fPrevFindString= ""; //$NON-NLS-1$ - - private class SearchResult { - int selection, length, index, findLength; - boolean found, forward; - - public SearchResult() { - Point p= fTarget.getSelection(); - selection= p.x; - length= p.y; - index= fCurrentIndex; - findLength= fFindString.length(); - found= fFound; - forward= fForward; - } - - } - - private void saveState() { - fSessionStack.push(new SearchResult()); - } - - private void restoreState() { - - StyledText text= fTextViewer.getTextWidget(); - if (text == null || text.isDisposed()) - return; - - SearchResult searchResult= null; - if (!fSessionStack.empty()) - searchResult= (SearchResult) fSessionStack.pop(); - - if (searchResult == null) { - text.getDisplay().beep(); - return; - } - - // TODO: reverse searches should put the caret at the start of the selection, instead of the end - text.setSelectionRange(searchResult.selection, searchResult.length); - text.showSelection(); - - // relies on the contents of the StringBuffer - fFindString.setLength(searchResult.findLength); - fCurrentIndex= searchResult.index; - fFound= searchResult.found; - fForward= searchResult.forward; - - // Recalculate the indices - if (fFindString.length() < fCasePosition) - fCasePosition= -1; - if (fSessionStack.size() < fWrapPosition) - fWrapPosition= -1; - } - - /** - * Sets the direction for the next search. - * This can be called before <code>beginSession</code> to set the initial search direction. - * @param forward <code>true</code> if the next search should be forward - * @see beginSession - */ - public void setDirection(boolean forward) { - fForward= forward; - } - - /** - * Creates an instance of an incremental find target. - * @param viewer the text viewer to operate on - * @param manager the status line manager for output - */ - public IncrementalFindTarget(ITextViewer viewer, IStatusLineManager manager) { - Assert.isNotNull(viewer); - Assert.isNotNull(manager); - fTextViewer= viewer; - fStatusLine= manager; - fTarget= viewer.getFindReplaceTarget(); - } - - /* - * @see IFindReplaceTarget#canPerformFind() - */ - public boolean canPerformFind() { - return fTarget.canPerformFind(); - } - - /* - * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean) - */ - public int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord) { - return fTarget.findAndSelect(offset, findString, searchForward, caseSensitive, wholeWord); - } - - /* - * @see IFindReplaceTarget#getSelection() - */ - public Point getSelection() { - return fTarget.getSelection(); - } - - /* - * @see IFindReplaceTarget#getSelectionText() - */ - public String getSelectionText() { - return fTarget.getSelectionText(); - } - - /* - * @see IFindReplaceTarget#isEditable() - */ - public boolean isEditable() { - return false; - } - - /* - * @see IFindReplaceTarget#replaceSelection(String) - */ - public void replaceSelection(String text) { - } - - /* - * @see IFindReplaceTargetExtension#beginSession() - */ - public void beginSession() { - fSearching= true; - - // Workaround since some accelerators get handled directly by the OS - if (fInstalled) { - saveState(); - repeatSearch(fForward); - updateStatus(); - fSearching= false; - return; - } - - fFindString.setLength(0); - fSessionStack= new Stack(); - fCasePosition= -1; - fWrapPosition= -1; - fFound= true; - - // clear initial selection - StyledText text= fTextViewer.getTextWidget(); - if (text != null && !text.isDisposed()) { - fCurrentIndex= text.getCaretOffset(); - text.setSelection(fCurrentIndex); - } else { - fCurrentIndex= 0; - } - - install(); - - // Set the mark - if (fTextViewer instanceof ITextViewerExtension) - ((ITextViewerExtension) fTextViewer).setMark(fCurrentIndex); - - updateStatus(); - - if (fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).beginSession(); - - fSearching= false; - } - - /* - * @see IFindReplaceTargetExtension#endSession() - */ - public void endSession() { - if (fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).endSession(); - - // will uninstall itself - } - - /* - * @see IFindReplaceTargetExtension#getScope() - */ - public IRegion getScope() { - return null; - } - - /* - * @see IFindReplaceTargetExtension#setGlobal(boolean) - */ - public void setGlobal(boolean global) { - } - - /* - * @see IFindReplaceTargetExtension#setScope(IRegion) - */ - public void setScope(IRegion scope) { - } - - /* - * @see IFindReplaceTargetExtension#setReplaceAllMode(boolean) - */ - public void setReplaceAllMode(boolean replaceAll) { - } - - /** - * Installs this target. I.e. adds all required listeners. - */ - private void install() { - - if (fInstalled) - return; - - StyledText text= fTextViewer.getTextWidget(); - if (text == null) - return; - - text.addMouseListener(this); - text.addFocusListener(this); - fTextViewer.addTextListener(this); - - ISelectionProvider selectionProvider= fTextViewer.getSelectionProvider(); - if (selectionProvider != null) - selectionProvider.addSelectionChangedListener(this); - - if (fTextViewer instanceof ITextViewerExtension) - ((ITextViewerExtension) fTextViewer).prependVerifyKeyListener(this); - else - text.addVerifyKeyListener(this); - - fInstalled= true; - } - - /** - * Uninstalls itself. I.e. removes all listeners installed in <code>install</code>. - */ - private void uninstall() { - - fTextViewer.removeTextListener(this); - - ISelectionProvider selectionProvider= fTextViewer.getSelectionProvider(); - if (selectionProvider != null) - selectionProvider.removeSelectionChangedListener(this); - - StyledText text= fTextViewer.getTextWidget(); - if (text != null) { - text.removeMouseListener(this); - text.removeFocusListener(this); - } - - if (fTextViewer instanceof ITextViewerExtension) { - ((ITextViewerExtension) fTextViewer).removeVerifyKeyListener(this); - - } else { - if (text != null) - text.removeVerifyKeyListener(this); - } - - fInstalled= false; - } - - /** - * Updates the status line. - */ - private void updateStatus() { - - if (!fInstalled) - return; - - String string= fFindString.toString(); - String wrapPrefix= fWrapPosition == -1 ? "" : WRAPPED; //$NON-NLS-1$ - String reversePrefix= fForward ? "" : REVERSE; //$NON-NLS-1$ - - if (!fFound) { - String pattern= EditorMessages.getString("Editor.FindIncremental.not_found.pattern"); //$NON-NLS-1$ - statusError(MessageFormat.format(pattern, new Object[] { reversePrefix, wrapPrefix, string })); - - } else { - String pattern= EditorMessages.getString("Editor.FindIncremental.found.pattern"); //$NON-NLS-1$ - statusMessage(MessageFormat.format(pattern, new Object[] { reversePrefix, wrapPrefix, string })); - } - } - - /* - * @see VerifyKeyListener#verifyKey(VerifyEvent) - */ - public void verifyKey(VerifyEvent event) { - - if (!event.doit) - return; - - fSearching= true; - if (event.character == 0) { - - switch (event.keyCode) { - - // ALT, CTRL, ARROW_LEFT, ARROW_RIGHT == leave - case SWT.ARROW_LEFT: - case SWT.ARROW_RIGHT: - case SWT.ARROW_UP: - case SWT.ARROW_DOWN: - case SWT.HOME: - case SWT.END: - case SWT.PAGE_DOWN: - case SWT.PAGE_UP: - leave(); - break; -/* - case SWT.ARROW_DOWN: - saveState(); - setDirection(true); - repeatSearch(fForward); - updateStatus(); - event.doit= false; - break; - - case SWT.ARROW_UP: - saveState(); - setDirection(false); - repeatSearch(fForward); - updateStatus(); - event.doit= false; - break; -*/ - } - - // event.character != 0 - } else { - - switch (event.character) { - - // ESC, CR = quit - case 0x1B: - case 0x0D: - leave(); - event.doit= false; - break; - - // backspace and delete - case 0x08: - case 0x7F: - restoreState(); - event.doit= false; - break; - - default: - if (event.stateMask == 0 || event.stateMask == SWT.SHIFT) { - saveState(); - addCharSearch(event.character); - event.doit= false; - } - break; - } - } - updateStatus(); - fSearching= false; - } - - /** - * Repeats the last search while possibly changing the direciton. - * @param forward <code>true</code> iff the next search should be forward - */ - private boolean repeatSearch(boolean forward) { - if (fFindString.length() == 0) - fFindString= new StringBuffer(fPrevFindString); - - String string= fFindString.toString(); - if (string.length() == 0) { - fFound= true; - return true; - } - - StyledText text= fTextViewer.getTextWidget(); - // Cannot use fTarget.getSelection since that does not return which side of the - // selection the caret is on. - int startIndex= text.getCaretOffset(); - if (!forward) - startIndex -= 1; - - // Check to see if a wrap is necessary - if (!fFound && (fForward == forward)) { - startIndex= -1; - if (fWrapPosition == -1) - fWrapPosition= fSessionStack.size(); - } - fForward = forward; - - // Find the string - text.setRedraw(false); - int index= fTarget.findAndSelect(startIndex, string, fForward, fCasePosition != -1, false); - - // Set the caret on the left if the search is reversed - if (!forward) { - Point p= fTarget.getSelection(); - text.setSelectionRange(p.x + p.y, -p.y); - p= null; - } - text.setRedraw(true); - - // Take appropriate action - boolean found = (index != -1); - if (!found && fFound) { - text= fTextViewer.getTextWidget(); - if (text != null && !text.isDisposed()) - text.getDisplay().beep(); - } - - if (found) - fCurrentIndex= startIndex; - - fFound= found; - return found; - } - - /** - * Adds the given character to the search string and repeats the search with the last parameters. - * @param c the character to append to the search pattern - */ - private boolean addCharSearch(char c) { - // Add char to pattern - if (fCasePosition == -1 && Character.isUpperCase(c) && Character.toLowerCase(c) != c) - fCasePosition= fFindString.length(); - - fFindString.append(c); - String string= fFindString.toString(); - StyledText text= fTextViewer.getTextWidget(); - - text.setRedraw(false); - int index= fTarget.findAndSelect(fCurrentIndex, string, fForward, fCasePosition != -1, false); - - // Set the caret on the left if the search is reversed - if (!fForward) { - Point p= fTarget.getSelection(); - text.setSelectionRange(p.x + p.y, -p.y); - } - text.setRedraw(true); - - // Take appropriate action - boolean found = (index != -1); - if (!found && fFound) { - text= fTextViewer.getTextWidget(); - if (text != null && !text.isDisposed()) - text.getDisplay().beep(); - } - - fFound= found; - return found; - } - - /** - * Leaves this incremental search session. - */ - private void leave() { - if (fFindString.length() != 0) - fPrevFindString= fFindString.toString(); - statusClear(); - uninstall(); - fSessionStack = null; - } - - /* - * @see ITextListener#textChanged(TextEvent) - */ - public void textChanged(TextEvent event) { - leave(); - } - - /* - * @see MouseListener#mouseDoubleClick(MouseEvent) - */ - public void mouseDoubleClick(MouseEvent e) { - leave(); - } - - /* - * @see MouseListener#mouseDown(MouseEvent) - */ - public void mouseDown(MouseEvent e) { - leave(); - } - - /* - * @see MouseListener#mouseUp(MouseEvent) - */ - public void mouseUp(MouseEvent e) { - leave(); - } - - /* - * @see FocusListener#focusGained(FocusEvent) - */ - public void focusGained(FocusEvent e) { - leave(); - } - - /* - * @see FocusListener#focusLost(FocusEvent) - */ - public void focusLost(FocusEvent e) { - leave(); - } - - /** - * Sets the given string as status message, clears the status error message. - * @param string the status message - */ - private void statusMessage(String string) { - fStatusLine.setErrorMessage(""); //$NON-NLS-1$ - fStatusLine.setMessage(escapeTabs(string)); - } - - /** - * Sets the status error message, clears the status message. - * @param string the status error message - */ - private void statusError(String string) { - fStatusLine.setErrorMessage(escapeTabs(string)); - fStatusLine.setMessage(""); //$NON-NLS-1$ - } - - /** - * Clears the status message and the status error message. - */ - private void statusClear() { - fStatusLine.setErrorMessage(""); //$NON-NLS-1$ - fStatusLine.setMessage(""); //$NON-NLS-1$ - } - - /** - * Translates all tab characters into a proper status line presentation. - * @param string the string in which to translate the tabs - * @return the given string with all tab characters replace with a proper status line presentation - */ - private String escapeTabs(String string) { - StringBuffer buffer= new StringBuffer(); - - int begin= 0; - int end= string.indexOf('\t', begin); - - while (end >= 0) { - buffer.append(string.substring(begin, end)); - buffer.append(TAB); - begin= end + 1; - end= string.indexOf('\t', begin); - } - buffer.append(string.substring(begin)); - - return buffer.toString(); - } - - /* - * @see IFindReplaceTargetExtension#getLineSelection() - */ - public Point getLineSelection() { - if (fTarget instanceof IFindReplaceTargetExtension) - return ((IFindReplaceTargetExtension) fTarget).getLineSelection(); - - return null; // XXX should not return null - } - - /* - * @see IFindReplaceTargetExtension#setSelection(int, int) - */ - public void setSelection(int offset, int length) { - if (fTarget instanceof IFindReplaceTargetExtension) - ((IFindReplaceTargetExtension) fTarget).setSelection(offset, length); - } - - /* - * @see IFindReplaceTargetExtension#setScopeHighlightColor(Color) - */ - public void setScopeHighlightColor(Color color) { - } - - /* - * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent e) { - if (!fSearching) - leave(); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/InfoForm.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/InfoForm.java deleted file mode 100644 index 1f7362b4953..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/InfoForm.java +++ /dev/null @@ -1,227 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; - -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; - - -/** - * A form consisting of a title, a banner, and a info text. Banner and info text are - * separated by a separator line. This form must be handled like a SWT widget. - * @since 2.0 - */ -public class InfoForm { - - /** The form's root widget */ - private ScrolledComposite fScrolledComposite; - /** The background color */ - private Color fBackgroundColor; - /** The foreground color */ - private Color fForegroundColor; - /** The separator's color */ - private Color fSeparatorColor; - /** The form header */ - private Label fHeader; - /** The form banner */ - private Label fBanner; - /** The form text */ - private Label fText; - /** The preference change listener */ - private IPropertyChangeListener fPropertyChangeListener; - - /** - * Creates a new info form. - * @param parent the parent - */ - public InfoForm(Composite parent) { - - Display display= parent.getDisplay(); - fBackgroundColor= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); - fForegroundColor= display.getSystemColor(SWT.COLOR_LIST_FOREGROUND); - fSeparatorColor= new Color(display, 152, 170, 203); - - fPropertyChangeListener= new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - handlePropertyChange(event); - } - }; - JFaceResources.getFontRegistry().addListener(fPropertyChangeListener); - - fScrolledComposite= new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); - fScrolledComposite.setAlwaysShowScrollBars(false); - fScrolledComposite.setExpandHorizontal(true); - fScrolledComposite.setExpandVertical(true); - fScrolledComposite.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - JFaceResources.getFontRegistry().removeListener(fPropertyChangeListener); - fScrolledComposite= null; - fSeparatorColor.dispose(); - fSeparatorColor= null; - fHeader= null; - fBanner= null; - fText= null; - } - }); - - Composite composite= createComposite(fScrolledComposite); - composite.setLayout(new GridLayout()); - - fHeader= createHeader(composite, null); - createLabel(composite, null); - createLabel(composite, null); - - fBanner= createBanner(composite, null); - - Composite separator= createCompositeSeparator(composite); - GridData data= new GridData(GridData.FILL_HORIZONTAL); - data.heightHint= 2; - separator.setLayoutData(data); - - fText= createLabel(composite, null); - createLabel(composite, null); - - fScrolledComposite.setContent(composite); - fScrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - - createActionControls(composite); - } - - /** - * Hook method for creating an appropriate action control. - * @param parent the action control's parent control - */ - protected void createActionControls(Composite parent) { - } - - /** - * Returns the control of this form. - * @return the root control of this form - */ - public Control getControl() { - return fScrolledComposite; - } - - /** - * Sets the header text of this info form. - * @param header the header text - */ - public void setHeaderText(String header) { - fHeader.setText(header); - } - - /** - * Sets the banner text of this info form. - * @param banner the banner text - */ - public void setBannerText(String banner) { - fBanner.setText(banner); - } - - /** - * Sets the info of this info form - * @param info the info text - */ - public void setInfo(String info) { - fText.setText(info); - } - - /* - * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) - */ - protected void handlePropertyChange(PropertyChangeEvent event) { - - if (fHeader != null) - fHeader.setFont(JFaceResources.getHeaderFont()); - - if (fBanner != null) - fBanner.setFont(JFaceResources.getBannerFont()); - - Control control= fScrolledComposite.getContent(); - fScrolledComposite.setMinSize(control.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - fScrolledComposite.setContent(control); - - fScrolledComposite.layout(true); - fScrolledComposite.redraw(); - } - - /* - * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createComposite(Composite) - */ - private Composite createComposite(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setBackground(fBackgroundColor); - return composite; - } - - /* - * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createCompositeSeparator(Composite) - */ - private Composite createCompositeSeparator(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - composite.setBackground(fSeparatorColor); - return composite; - } - - /* - * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createLabel(Composite, String) - */ - private Label createLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.NONE); - if (text != null) - label.setText(text); - label.setBackground(fBackgroundColor); - label.setForeground(fForegroundColor); - return label; - } - - /* - * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createHeader(Composite, String) - */ - private Label createHeader(Composite parent, String text) { - Label label = new Label(parent, SWT.NONE); - if (text != null) - label.setText(text); - label.setBackground(fBackgroundColor); - label.setForeground(fForegroundColor); - label.setFont(JFaceResources.getHeaderFont()); - return label; - } - - /* - * @see org.eclipse.update.ui.forms.internal.FormWidgetFactory#createBanner(Composite, String) - */ - private Label createBanner(Composite parent, String text) { - Label label = new Label(parent, SWT.NONE); - if (text != null) - label.setText(text); - label.setBackground(fBackgroundColor); - label.setForeground(fForegroundColor); - label.setFont(JFaceResources.getBannerFont()); - return label; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkAction.java deleted file mode 100644 index 84d63b6fcdc..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkAction.java +++ /dev/null @@ -1,73 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.jface.text.IMarkRegionTarget; - -/** - * An action to handle emacs-like marked regions. - * @since 2.0 - */ -public class MarkAction extends TextEditorAction { - - /** Sets the mark. */ - public static final int SET_MARK= 0; - /** Clears the mark. */ - public static final int CLEAR_MARK= 1; - /** Swaps the mark and the cursor position. */ - public static final int SWAP_MARK= 2; - - /** The mark action type. */ - private final int fType; - - /** - * Constructor for MarkAction. - * - * @param type the mark action type, must be one of - * <code>SET_MARK</code>, <code>CLEAR_MARK</code> or <code>SWAP_MARK</code>. - */ - public MarkAction(ResourceBundle bundle, String prefix, ITextEditor editor, int type) { - super(bundle, prefix, editor); - fType= type; - } - - /* - * @see IAction#run() - */ - public void run() { - - ITextEditor editor= getTextEditor(); - if (editor == null) - return; - - IMarkRegionTarget target= (IMarkRegionTarget) editor.getAdapter(IMarkRegionTarget.class); - if (target == null) - return; - - switch (fType) { - case SET_MARK: - target.setMarkAtCursor(true); - break; - - case CLEAR_MARK: - target.setMarkAtCursor(false); - break; - - case SWAP_MARK: - target.swapMarkAndCursor(); - break; - } - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkRegionTarget.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkRegionTarget.java deleted file mode 100644 index 369f54184b7..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkRegionTarget.java +++ /dev/null @@ -1,107 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.swt.graphics.Point; - -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.text.IMarkRegionTarget; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITextViewerExtension; - -/** - * Default implementation of <code>IMarkRegionTarget</code> using <code>ITextViewer</code> - * and <code>IStatusLineManager</code>. - * @since 2.0 - */ -public class MarkRegionTarget implements IMarkRegionTarget { - - /** The text viewer. */ - private final ITextViewer fViewer; - /** The status line. */ - private final IStatusLineManager fStatusLine; - - /** - * Creates a MarkRegionTaret. - * - * @param viewer the text viewer - * @param manager the status line manager - */ - public MarkRegionTarget(ITextViewer viewer, IStatusLineManager manager) { - fViewer= viewer; - fStatusLine= manager; - } - - /* - * @see IMarkregion#setMarkAtCursor(boolean) - */ - public void setMarkAtCursor(boolean set) { - - if (!(fViewer instanceof ITextViewerExtension)) - return; - - ITextViewerExtension viewerExtension= ((ITextViewerExtension) fViewer); - - if (set) { - Point selection= fViewer.getSelectedRange(); - viewerExtension.setMark(selection.x); - - fStatusLine.setErrorMessage(""); //$NON-NLS-1$ - fStatusLine.setMessage(EditorMessages.getString("Editor.mark.status.message.mark.set")); //$NON-NLS-1$ - - } else { - viewerExtension.setMark(-1); - - fStatusLine.setErrorMessage(""); //$NON-NLS-1$ - fStatusLine.setMessage(EditorMessages.getString("Editor.mark.status.message.mark.cleared")); //$NON-NLS-1$ - } - } - - /* - * @see IMarkregion#swapMarkAndCursor() - */ - public void swapMarkAndCursor() { - - if (!(fViewer instanceof ITextViewerExtension)) - return; - - ITextViewerExtension viewerExtension= ((ITextViewerExtension) fViewer); - - int markPosition= viewerExtension.getMark(); - if (markPosition == -1) { - fStatusLine.setErrorMessage("mark not set"); - fStatusLine.setMessage(""); //$NON-NLS-1$ - return; - } - - IRegion region= fViewer.getVisibleRegion(); - int offset= region.getOffset(); - int length= region.getLength(); - - if (markPosition < offset || markPosition > offset + length) { - fStatusLine.setErrorMessage("mark not in visible region"); - fStatusLine.setMessage(""); //$NON-NLS-1$ - return; - } - - Point selection= fViewer.getSelectedRange(); - viewerExtension.setMark(selection.x); - - fViewer.setSelectedRange(markPosition, 0); - fViewer.revealRange(markPosition, 0); - - fStatusLine.setErrorMessage(""); //$NON-NLS-1$ - fStatusLine.setMessage(EditorMessages.getString("Editor.mark.status.message.mark.swapped")); //$NON-NLS-1$ - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerAnnotation.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerAnnotation.java deleted file mode 100644 index c531c2a39ac..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerAnnotation.java +++ /dev/null @@ -1,262 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.swt.SWT; -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.core.resources.IMarker; - -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.model.IWorkbenchAdapter; - - -/** - * Annotation representing a marker on a resource in the workspace. - * This class may be instantiated or be subclassed. - * - * @see IMarker - */ -public class MarkerAnnotation extends Annotation { - - /** - * The layer in which markers representing problem are located. - * @since 2.0 - */ - public final static int PROBLEM_LAYER= 5; - - /** Internal image registry */ - private static Map fgImageRegistry; - - /** - * Returns an image for the given display as specified by the given image descriptor. - * @param display the display - * @param descriptor the image descriptor - * @return an image for the display as specified by the descriptor - */ - protected static Image getImage(Display display, ImageDescriptor descriptor) { - Map map= getImageRegistry(display); - Image image= (Image) map.get(descriptor); - if (image == null) { - image= descriptor.createImage(); - map.put(descriptor, image); - } - return image; - } - - /** - * Returns an image registry for the given display. If no such registry exists - * the resgitry is created. - * @param display the display - * @return the image registry for the given display - */ - protected static Map getImageRegistry(Display display) { - if (fgImageRegistry == null) { - fgImageRegistry= new HashMap(); - display.disposeExec(new Runnable() { - public void run() { - if (fgImageRegistry != null) { - Map map= fgImageRegistry; - fgImageRegistry= null; - Iterator e= map.values().iterator(); - while (e.hasNext()) { - Image image= (Image) e.next(); - if (!image.isDisposed()) - image.dispose(); - } - } - } - }); - } - return fgImageRegistry; - } - - - /** The marker this annotation represents */ - private IMarker fMarker; - /** The image, i.e., visual presentation of this annotation */ - private Image fImage; - /** The image name */ - private String fImageName; - - /** - * Creates a new annotation for the given marker. - * - * @param marker the marker - */ - public MarkerAnnotation(IMarker marker) { - fMarker= marker; - initialize(); - } - - /** - * Sets the marker image to the given image. - * - * @param image the new marker image - */ - protected void setImage(Image image) { - fImage= image; - } - - /** - * The <code>MarkerAnnotation</code> implementation of this - * <code>Object</code> method returns <code>true</code> iff the other - * object is also a <code>MarkerAnnotation</code> and the marker handles are - * equal. - */ - public boolean equals(Object o) { - if (o != null && o.getClass() == getClass()) - return fMarker.equals(((MarkerAnnotation) o).fMarker); - return false; - } - - /* - * @see Object#hashCode - */ - public int hashCode() { - return fMarker.hashCode(); - } - - /** - * Returns this annotation's underlying marker. - * - * @return the marker - */ - public IMarker getMarker() { - return fMarker; - } - - /** - * Initializes the annotation's icon representation and its drawing layer - * based upon the properties of the underlying marker. - */ - protected void initialize() { - - String name= null; - int layer= -1; - - if (MarkerUtilities.isMarkerType(fMarker, IMarker.TASK)) { - name= ISharedImages.IMG_OBJS_TASK_TSK; - layer= 1; - } else if (MarkerUtilities.isMarkerType(fMarker, IMarker.BOOKMARK)) { - name= ISharedImages.IMG_OBJS_BKMRK_TSK; - layer= 2; - } else if (MarkerUtilities.isMarkerType(fMarker, IMarker.PROBLEM)) { - switch (fMarker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO)) { - case IMarker.SEVERITY_INFO: - name= ISharedImages.IMG_OBJS_INFO_TSK; - layer= 3; - break; - case IMarker.SEVERITY_WARNING: - layer= 3; - name= ISharedImages.IMG_OBJS_WARN_TSK; - break; - case IMarker.SEVERITY_ERROR: - layer= PROBLEM_LAYER; - name= ISharedImages.IMG_OBJS_ERROR_TSK; - break; - }; - } else { - name= getUnknownImageName(fMarker); - layer= 1; - } - - // setImage(getImage(name)); - fImage= null; - fImageName= name; - setLayer(layer); - } - - /* - * @see Annotation#paint - */ - public void paint(GC gc, Canvas canvas, Rectangle r) { - Image image= getImage(canvas.getDisplay()); - if (image != null) { - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19184 - drawImage(image, gc, canvas, r, SWT.CENTER, SWT.TOP); - } - } - - /** - * Informs this annotation about changes applied to its underlying marker - * and adapts to those changes. - */ - public void update() { - initialize(); - } - - /** - * Returns the name of an image used to visually represent markers of - * unknown type. This implementation returns <code>null</code>. - * Subclasses may replace this method. - * - * @param marker the marker of unkown type - * @return the name of an image for markers of unknown type. - */ - protected String getUnknownImageName(IMarker marker) { - return null; - } - - /** - * Returns the image of the given name. Subclasses may extend this method. - * If so, subclasses must assume responsibility for disposing the images - * they create. - * - * @param name the name of the requested image - * @return the image or <code>null</code> if there is no such image - */ - protected Image getImage(String name) { - if (name != null) - return PlatformUI.getWorkbench().getSharedImages().getImage(name); - return null; - } - - - /** - * Returns an image for this annotation. It first consults the workbench adapter - * for this annotation's marker. If none is defined, it tries to find an image for - * the image name of this annotation. - * - * @param display the display for which the image is requested - * @return the image for this annotation - */ - protected Image getImage(Display display) { - if (fImage == null) { - - IWorkbenchAdapter adapter= (IWorkbenchAdapter) fMarker.getAdapter(IWorkbenchAdapter.class); - if (adapter != null) { - ImageDescriptor descriptor= adapter.getImageDescriptor(fMarker); - if (descriptor != null) - fImage= getImage(display, descriptor); - } - - if (fImage == null) - fImage= getImage(fImageName); - - } - return fImage; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerAction.java deleted file mode 100644 index a92c57bd309..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerAction.java +++ /dev/null @@ -1,417 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.ResourceBundle; - -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; - -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IInputValidator; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.text.source.IVerticalRuler; -import org.eclipse.jface.text.source.IVerticalRulerInfo; -import org.eclipse.jface.window.Window; - -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.PlatformUI; - - - -/** - * A ruler action which can add and remove markers which have a visual - * representation in the ruler. - * <p> - * This class may be instantiated but is not intended for subclassing. - * </p> - */ -public class MarkerRulerAction extends ResourceAction implements IUpdate { - - /** The vertical ruler info of the editor */ - private IVerticalRulerInfo fRuler; - /** The associated editor */ - private ITextEditor fTextEditor; - /** The of the marker to be created/removed */ - private String fMarkerType; - /** The cached list of markers covering a particular vertical ruler position */ - private List fMarkers; - /** The flag indicating whether user interaction is required. */ - private boolean fAskForLabel; - /** The action's resource bundle */ - private ResourceBundle fBundle; - /** The prefix used for resource bundle look ups */ - private String fPrefix; - /** The cached action label when adding a marker */ - private String fAddLabel; - /** The cached action label when removing a marker */ - private String fRemoveLabel; - - - /** - * Creates a new action for the given ruler and editor. The action configures - * its visual representation from the given resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or <code>null</code> if none - * @param editor the editor - * @param ruler the ruler - * @param markerType the type of marker - * @param askForLabel <code>true</code> if the user should be asked for a label when a new marker is created - * @see ResourceAction#ResourceAction - * @since 2.0 - */ - public MarkerRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler, String markerType, boolean askForLabel) { - super(bundle, prefix); - fRuler= ruler; - fTextEditor= editor; - fMarkerType= markerType; - fAskForLabel= askForLabel; - - fBundle= bundle; - fPrefix= prefix; - - fAddLabel= getString(bundle, prefix + "add.label", prefix + "add.label"); //$NON-NLS-2$ //$NON-NLS-1$ - fRemoveLabel= getString(bundle, prefix + "remove.label", prefix + "remove.label"); //$NON-NLS-2$ //$NON-NLS-1$ - } - - /** - * @deprecated use <code>MarkerRulerAction(ResourceBundle, String, ITextEditor, IVerticalRulerInfo, String, boolean)</code> instead - */ - public MarkerRulerAction(ResourceBundle bundle, String prefix, IVerticalRuler ruler, ITextEditor editor, String markerType, boolean askForLabel) { - this(bundle, prefix, editor, ruler, markerType, askForLabel); - } - - - /** - * Returns this action's editor. - * - * @return this action's editor - */ - protected ITextEditor getTextEditor() { - return fTextEditor; - } - - /** - * Returns this action's vertical ruler. - * - * @return this action's vertical ruler - * @deprecated use <code>getVerticalRulerInfo</code> instead - */ - protected IVerticalRuler getVerticalRuler() { - if (fRuler instanceof IVerticalRuler) - return (IVerticalRuler) fRuler; - return null; - } - - /** - * Returns this action's vertical ruler info. - * - * @return this action's vertical ruler info - * @since 2.0 - */ - protected IVerticalRulerInfo getVerticalRulerInfo() { - return fRuler; - } - - /** - * Returns this action's resource bundle. - * - * @return this action's resource bundle - */ - protected ResourceBundle getResourceBundle() { - return fBundle; - } - - /** - * Returns this action's resource key prefix. - * - * @return this action's resource key prefix - */ - protected String getResourceKeyPrefix() { - return fPrefix; - } - - /* - * @see IUpdate#update() - */ - public void update() { - fMarkers= getMarkers(); - setText(fMarkers.isEmpty() ? fAddLabel : fRemoveLabel); - } - - /* - * @see Action#run() - */ - public void run() { - if (fMarkers.isEmpty()) - addMarker(); - else - removeMarkers(fMarkers); - } - - /** - * Returns the resource for which to create the marker, - * or <code>null</code> if there is no applicable resource. - * - * @return the resource for which to create the marker or <code>null</code> - */ - protected IResource getResource() { - IEditorInput input= fTextEditor.getEditorInput(); - - IResource resource= (IResource) input.getAdapter(IFile.class); - - if (resource == null) - resource= (IResource) input.getAdapter(IResource.class); - - return resource; - } - - /** - * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input. - * - * @return the marker annotation model - */ - protected AbstractMarkerAnnotationModel getAnnotationModel() { - IDocumentProvider provider= fTextEditor.getDocumentProvider(); - IAnnotationModel model= provider.getAnnotationModel(fTextEditor.getEditorInput()); - if (model instanceof AbstractMarkerAnnotationModel) - return (AbstractMarkerAnnotationModel) model; - return null; - } - - /** - * Returns the <code>IDocument</code> of the editor's input. - * - * @return the document of the editor's input - */ - protected IDocument getDocument() { - IDocumentProvider provider= fTextEditor.getDocumentProvider(); - return provider.getDocument(fTextEditor.getEditorInput()); - } - - /** - * Checks whether a position includes the ruler's line of activity. - * - * @param position the position to be checked - * @param document the document the position refers to - * @return <code>true</code> if the line is included by the given position - */ - protected boolean includesRulerLine(Position position, IDocument document) { - - if (position != null) { - try { - int markerLine= document.getLineOfOffset(position.getOffset()); - int line= fRuler.getLineOfLastMouseButtonActivity(); - if (line == markerLine) - return true; - // commented because of "1GEUOZ9: ITPJUI:ALL - Confusing UI for multiline Bookmarks and Tasks" - // return (markerLine <= line && line <= document.getLineOfOffset(position.getOffset() + position.getLength())); - } catch (BadLocationException x) { - } - } - - return false; - } - - /** - * Handles core exceptions. This implementation logs the exceptions - * with the workbech plugin and shows an error dialog. - * - * @param exception the exception to be handled - * @param message the message to be logged with the given exception - */ - protected void handleCoreException(CoreException exception, String message) { - ILog log= Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog(); - - if (message != null) - log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, message, null)); - - log.log(exception.getStatus()); - - - Shell shell= getTextEditor().getSite().getShell(); - String title= getString(fBundle, fPrefix + "error.dialog.title", fPrefix + "error.dialog.title"); //$NON-NLS-2$ //$NON-NLS-1$ - String msg= getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$ - - ErrorDialog.openError(shell, title, msg, exception.getStatus()); - } - - /** - * Returns all markers which include the ruler's line of activity. - * - * @return all markers which include the ruler's line of activity - */ - protected List getMarkers() { - - List markers= new ArrayList(); - - IResource resource= getResource(); - IDocument document= getDocument(); - AbstractMarkerAnnotationModel model= getAnnotationModel(); - - if (resource != null && model != null && resource.exists()) { - try { - IMarker[] allMarkers= resource.findMarkers(fMarkerType, true, IResource.DEPTH_ZERO); - if (allMarkers != null) { - for (int i= 0; i < allMarkers.length; i++) { - if (includesRulerLine(model.getMarkerPosition(allMarkers[i]), document)) { - markers.add(allMarkers[i]); - } - } - } - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("MarkerRulerAction.getMarker")); //$NON-NLS-1$ - } - } - - return markers; - } - - /** - * Creates a new marker according to the specification of this action and - * adds it to the marker resource. - */ - protected void addMarker() { - IResource resource= getResource(); - if (resource == null) - return; - Map attributes= getInitialAttributes(); - if (fAskForLabel) { - if (!askForLabel(attributes)) - return; - } - - try { - MarkerUtilities.createMarker(resource, attributes, fMarkerType); - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("MarkerRulerAction.addMarker")); //$NON-NLS-1$ - } - } - - /** - * Removes the given markers. - * - * @param markers the markers to be deleted - */ - protected void removeMarkers(final List markers) { - try { - getResource().getWorkspace().run(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - for (int i= 0; i < markers.size(); ++i) { - IMarker marker= (IMarker) markers.get(i); - marker.delete(); - } - } - }, null); - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("MarkerRulerAction.removeMarkers")); //$NON-NLS-1$ - } - } - - /** - * Asks the user for a marker label. Returns <code>true</code> if a label - * is entered, <code>false</code> if the user cancels the input dialog. - * Sets the value of the attribute <code>message</code> in the given - * map of attributes. - * - * @param attributes the map of attributes - * @return <code>true</code> if the map of attributes has successfuly been initialized - */ - protected boolean askForLabel(Map attributes) { - - Object o= attributes.get("message"); //$NON-NLS-1$ - String proposal= (o instanceof String) ? (String) o : ""; //$NON-NLS-1$ - if (proposal == null) - proposal= ""; //$NON-NLS-1$ - - String title= getString(fBundle, fPrefix + "add.dialog.title", fPrefix + "add.dialog.title"); //$NON-NLS-2$ //$NON-NLS-1$ - String message= getString(fBundle, fPrefix + "add.dialog.message", fPrefix + "add.dialog.message"); //$NON-NLS-2$ //$NON-NLS-1$ - IInputValidator inputValidator = new IInputValidator() { - public String isValid(String newText) { - return (newText == null || newText.length() == 0) ? " " : null; //$NON-NLS-1$ - } - }; - InputDialog dialog= new InputDialog(fTextEditor.getSite().getShell(), title, message, proposal, inputValidator); - - String label= null; - if (dialog.open() != Window.CANCEL) - label= dialog.getValue(); - - if (label == null) - return false; - - label= label.trim(); - if (label.length() == 0) - return false; - - MarkerUtilities.setMessage(attributes, label); - return true; - } - - /** - * Returns the attributes with which a newly created marker will be - * initialized. - * - * @return the initial marker attributes - */ - protected Map getInitialAttributes() { - - Map attributes= new HashMap(11); - - IDocumentProvider provider= fTextEditor.getDocumentProvider(); - IDocument document= provider.getDocument(fTextEditor.getEditorInput()); - int line= fRuler.getLineOfLastMouseButtonActivity(); - int start= -1; - int end= -1; - - try { - - IRegion lineInformation= document.getLineInformation(line); - start= lineInformation.getOffset(); - int length= lineInformation.getLength(); - - end= start + length; - - } catch (BadLocationException x) { - } - - // marker line numbers are 1-based - MarkerUtilities.setLineNumber(attributes, line + 1); - MarkerUtilities.setCharStart(attributes, start); - MarkerUtilities.setCharEnd(attributes, end); - - return attributes; - } -} - diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerInfoAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerInfoAction.java deleted file mode 100644 index 9a19004249d..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerRulerInfoAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; -import org.eclipse.jface.text.source.IVerticalRulerInfo; - - -/** - * @deprecated use <code>MarkerRulerAction</code> instead - * @since 2.0 - */ -public class MarkerRulerInfoAction extends MarkerRulerAction { - - /** - * @deprecated use super class instead - */ - public MarkerRulerInfoAction(ResourceBundle bundle, String prefix, IVerticalRulerInfo ruler, ITextEditor editor, String markerType, boolean askForLabel) { - super(bundle, prefix, editor, ruler, markerType, askForLabel); - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUpdater.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUpdater.java deleted file mode 100644 index 5a18799e1cf..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUpdater.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - -import org.eclipse.core.resources.IMarker; - -/** - * Updates a marker's positional attributes which are start position, end position, - * and line number. - */ -class MarkerUpdater implements IMarkerUpdater { - - private final static String[] ATTRIBUTES= {IMarker.CHAR_START, IMarker.CHAR_END, IMarker.LINE_NUMBER}; - - /* - * @see IMarkerUpdater#getAttribute() - */ - public String[] getAttribute() { - return ATTRIBUTES; - } - - /* - * @see IMarkerUpdater#getMarkerType() - */ - public String getMarkerType() { - return null; - } - - /* - * @see IMarkerUpdater#updateMarker(IMarker, IDocument, Position) - */ - public boolean updateMarker(IMarker marker, IDocument document, Position position) { - - if (position.isDeleted()) - return false; - - if (MarkerUtilities.getCharStart(marker) != -1 && MarkerUtilities.getCharEnd(marker) != -1) { - MarkerUtilities.setCharStart(marker, position.getOffset()); - MarkerUtilities.setCharEnd(marker, position.getOffset() + position.getLength()); - } - if (MarkerUtilities.getLineNumber(marker) != -1) { - try { - // marker line numbers are 1-based - MarkerUtilities.setLineNumber(marker, document.getLineOfOffset(position.getOffset()) + 1); - } catch (BadLocationException x) { - } - } - - return true; - } - -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUtilities.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUtilities.java deleted file mode 100644 index c67c7ee0736..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/MarkerUtilities.java +++ /dev/null @@ -1,242 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.Map; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; - -import org.eclipse.ui.PlatformUI; - - - -/** - * Utility class for accessing marker attributes. The static methods provided - * on this class provide internal exception handling (unexpected - * <code>CoreException</code>s are logged to workbench). - * <p> - * This class provides static methods only; it is not intended to be - * instantiated or subclassed by clients. - * </p> - */ -public final class MarkerUtilities { - - /** - * Don't allow instantiation. - */ - private MarkerUtilities() { - } - - /** - * Returns the ending character offset of the given marker. - * - * @param marker the marker - * @return the ending character offset, or <code>-1</code> if not set - * @see IMarker#CHAR_END - * @see IMarker#getAttribute(java.lang.String,int) - */ - public static int getCharEnd(IMarker marker) { - return getIntAttribute(marker, IMarker.CHAR_END, -1); - } - - /** - * Returns the starting character offset of the given marker. - * - * @param marker the marker - * @return the starting character offset, or <code>-1</code> if not set - * @see IMarker#CHAR_START - * @see IMarker#getAttribute(java.lang.String,int) - */ - public static int getCharStart(IMarker marker) { - return getIntAttribute(marker, IMarker.CHAR_START, -1); - } - - /** - * Returns the specified attribute of the given marker as an integer. - * Returns the given default if the attribute value is not an integer. - */ - private static int getIntAttribute(IMarker marker, String attributeName, int defaultValue) { - return marker.getAttribute(attributeName, defaultValue); - } - - /** - * Returns the line number of the given marker. - * - * @param marker the marker - * @return the line number, or <code>-1</code> if not set - * @see IMarker#LINE_NUMBER - * @see IMarker#getAttribute(java.lang.String,int) - */ - public static int getLineNumber(IMarker marker) { - return getIntAttribute(marker, IMarker.LINE_NUMBER, -1); - } - - /** - * Returns the priority of the given marker. - * - * @param marker the marker - * @return the priority, or <code>IMarker.PRIORITY_NORMAL</code> if not set - * @see IMarker#PRIORITY - * @see IMarker#PRIORITY_NORMAL - * @see IMarker#getAttribute(java.lang.String,int) - */ - public static int getPriority(IMarker marker) { - return getIntAttribute(marker, IMarker.PRIORITY, IMarker.PRIORITY_NORMAL); - } - - /** - * Handles a core exception which occurs when accessing marker attributes. - */ - private static void handleCoreException(CoreException e) { - Platform.getPlugin(PlatformUI.PLUGIN_ID).getLog().log(e.getStatus()); - } - - /** - * Returns whether the given marker is of the given type (either directly or indirectly). - * - * @param marker the marker to be checked - * @param type the reference type - * @return <code>true</code>if maker is an instance of the reference type - */ - public static boolean isMarkerType(IMarker marker, String type) { - try { - return marker.isSubtypeOf(type); - } catch (CoreException e) { - handleCoreException(e); - return false; - } - } - - /** - * Sets the ending character offset of the given marker. - * - * @param marker the marker - * @param charEnd the ending character offset - * @see IMarker#CHAR_END - * @see IMarker#setAttribute(java.lang.String,int) - */ - public static void setCharEnd(IMarker marker, int charEnd) { - setIntAttribute(marker, IMarker.CHAR_END, charEnd); - } - - /** - * Sets the ending character offset in the given map using the standard - * marker attribute name as the key. - * - * @param map the map (key type: <code>String</code>, value type: - * <code>Object</code>) - * @param charEnd the ending character offset - * @see IMarker#CHAR_END - */ - public static void setCharEnd(Map map, int charEnd) { - map.put(IMarker.CHAR_END, new Integer(charEnd)); - } - - /** - * Sets the starting character offset of the given marker. - * - * @param marker the marker - * @param charStart the starting character offset - * @see IMarker#CHAR_START - * @see IMarker#setAttribute(java.lang.String,int) - */ - public static void setCharStart(IMarker marker, int charStart) { - setIntAttribute(marker, IMarker.CHAR_START, charStart); - } - - /** - * Sets the starting character offset in the given map using the standard - * marker attribute name as the key. - * - * @param map the map (key type: <code>String</code>, value type: - * <code>Object</code>) - * @param charStart the starting character offset - * @see IMarker#CHAR_START - */ - public static void setCharStart(Map map, int charStart) { - map.put(IMarker.CHAR_START, new Integer(charStart)); - } - - /** - * Sets the specified attribute of the given marker as an integer. - */ - private static void setIntAttribute(IMarker marker, String attributeName, int value) { - try { - marker.setAttribute(attributeName, value); - } catch (CoreException e) { - handleCoreException(e); - } - } - - /** - * Sets the line number of the given marker. - * - * @param marker the marker - * @param lineNum the line number - * @see IMarker#LINE_NUMBER - * @see IMarker#setAttribute(java.lang.String,int) - */ - public static void setLineNumber(IMarker marker, int lineNum) { - setIntAttribute(marker, IMarker.LINE_NUMBER, lineNum); - } - - /** - * Sets the line number in the given map using the standard marker attribute - * name as the key. - * - * @param map the map (key type: <code>String</code>, value type: - * <code>Object</code>) - * @param lineNum the line number - * @see IMarker#LINE_NUMBER - */ - public static void setLineNumber(Map map, int lineNum) { - map.put(IMarker.LINE_NUMBER, new Integer(lineNum)); - } - - /** - * Sets the message in the given map using the standard marker attribute name - * as the key. - * - * @param map the map (key type: <code>String</code>, value type: - * <code>Object</code>) - * @param message the message - * @see IMarker#MESSAGE - */ - public static void setMessage(Map map, String message) { - map.put(IMarker.MESSAGE, message); - } - - /** - * Creates a marker on the given resource with the given type and attributes. - * <p> - * This method modifies the workspace (progress is not reported to the user). - * </p> - * - * @param resource the resource - * @param attributes the attribute map (key type: <code>String</code>, - * value type: <code>Object</code>) - * @param markerType the type of marker - * @exception CoreException if this method fails - * @see IResource#createMarker - */ - public static void createMarker(final IResource resource, final Map attributes, final String markerType) throws CoreException { - - IWorkspaceRunnable r= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - IMarker marker= resource.createMarker(markerType); - marker.setAttributes(attributes); - } - }; - - resource.getWorkspace().run(r, null); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/PropagatingFontFieldEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/PropagatingFontFieldEditor.java deleted file mode 100644 index a9f76ce480b..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/PropagatingFontFieldEditor.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.swt.widgets.Composite; - - -/** - * @deprecated use WorkbenchChainedTextFontFieldEditor - */ -public final class PropagatingFontFieldEditor extends WorkbenchChainedTextFontFieldEditor { - - /** - * @deprecated use WorkbenchChainedTextFontFieldEditor - */ - public PropagatingFontFieldEditor(String name, String labelText, Composite parent) { - super(name, labelText, parent); - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java deleted file mode 100644 index f03712d7ad8..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.resource.ImageDescriptor; - -import org.eclipse.ui.help.WorkbenchHelp; - - -/** - * An action which configures its label, image, tooltip, and description from - * a resource bundle using known keys. - * <p> - * Clients may subclass this abstract class to define new kinds of actions. As - * with <code>Action</code>, subclasses must implement the - * <code>IAction.run</code> method to carry out the action's semantics. - * </p> - */ -public abstract class ResourceAction extends Action { - - /** - * Retrieves and returns the value with the given key from the given resource - * bundle, or returns the given default value if there is no such resource. - * Convenience method for dealing gracefully with missing resources. - * - * @param bundle the resource bundle - * @param key the resource key - * @param defaultValue the default value, or <code>null</code> - * @return the resource value, or the given default value (which may be - * <code>null</code>) - */ - protected static String getString(ResourceBundle bundle, String key, String defaultValue) { - - String value= defaultValue; - try { - value= bundle.getString(key); - } catch (MissingResourceException x) { - } - - return value; - } - - /** - * Creates a new action that configures itself from the given resource - * bundle. - * <p> - * The following keys, prepended by the given option prefix, - * are used for retrieving resources from the given bundle: - * <ul> - * <li><code>"label"</code> - <code>setText</code></li> - * <li><code>"tooltip"</code> - <code>setToolTipText</code></li> - * <li><code>"image"</code> - <code>setImageDescriptor</code></li> - * <li><code>"description"</code> - <code>setDescription</code></li> - * </ul> - * </p> - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys, or - * <code>null</code> if none - */ - public ResourceAction(ResourceBundle bundle, String prefix) { - super(); - - String labelKey= "label"; //$NON-NLS-1$ - String tooltipKey= "tooltip"; //$NON-NLS-1$ - String imageKey= "image"; //$NON-NLS-1$ - String descriptionKey= "description"; //$NON-NLS-1$ - - if (prefix != null && prefix.length() > 0) { - labelKey= prefix + labelKey; - tooltipKey= prefix + tooltipKey; - imageKey= prefix + imageKey; - descriptionKey= prefix + descriptionKey; - } - - setText(getString(bundle, labelKey, labelKey)); - setToolTipText(getString(bundle, tooltipKey, null)); - setDescription(getString(bundle, descriptionKey, null)); - - String file= getString(bundle, imageKey, null); - if (file != null && file.trim().length() > 0) - setImageDescriptor(ImageDescriptor.createFromFile(getClass(), file)); - } - - /** - * Sets the action's help context id. - * - * @param contextId the help context id - */ - public final void setHelpContextId(String contextId) { - WorkbenchHelp.setHelp(this, contextId); - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceMarkerAnnotationModel.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceMarkerAnnotationModel.java deleted file mode 100644 index a934e68af3a..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceMarkerAnnotationModel.java +++ /dev/null @@ -1,171 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.jface.util.Assert; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - - - -/** - * A marker annotation model whose underlying source of markers is - * a resource in the workspace. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - */ -public class ResourceMarkerAnnotationModel extends AbstractMarkerAnnotationModel { - - - /** - * Internal resource change listener. - */ - class ResourceChangeListener implements IResourceChangeListener { - /* - * @see IResourceChangeListener#resourceChanged - */ - public void resourceChanged(IResourceChangeEvent e) { - IResourceDelta delta= e.getDelta(); - try { - if (delta != null) - delta.accept(fResourceDeltaVisitor); - } catch (CoreException x) { - handleCoreException(x, EditorMessages.getString("ResourceMarkerAnnotationModel.resourceChanged")); //$NON-NLS-1$ - } - } - }; - - /** - * Internal resource delta visitor. - */ - class ResourceDeltaVisitor implements IResourceDeltaVisitor { - /* - * @see IResourceDeltaVisitor#visit - */ - public boolean visit(IResourceDelta delta) throws CoreException { - if (delta != null && fResource.equals(delta.getResource())) { - update(delta.getMarkerDeltas()); - return false; - } - return true; - } - }; - - /** The workspace */ - private IWorkspace fWorkspace; - /** The resource */ - private IResource fResource; - /** The resource change listener */ - private IResourceChangeListener fResourceChangeListener= new ResourceChangeListener(); - /** The resource delta visitor */ - private IResourceDeltaVisitor fResourceDeltaVisitor= new ResourceDeltaVisitor(); - - - /** - * Creates a marker annotation model with the given resource as the source - * of the markers. - * - * @param resource the resource - */ - public ResourceMarkerAnnotationModel(IResource resource) { - Assert.isNotNull(resource); - fResource= resource; - fWorkspace= resource.getWorkspace(); - } - - /* - * @see AnnotationModel#isAcceptable - */ - protected boolean isAcceptable(IMarker marker) { - return marker != null && fResource.equals(marker.getResource()); - } - - /** - * Updates this model to the given marker deltas. - * - * @param markerDeltas the list of marker deltas - */ - private void update(IMarkerDelta[] markerDeltas) { - - if (markerDeltas.length == 0) - return; - - for (int i= 0; i < markerDeltas.length; i++) { - IMarkerDelta delta= markerDeltas[i]; - switch (delta.getKind()) { - case IResourceDelta.ADDED : - addMarkerAnnotation(delta.getMarker()); - break; - case IResourceDelta.REMOVED : - removeMarkerAnnotation(delta.getMarker()); - break; - case IResourceDelta.CHANGED : - modifyMarkerAnnotation(delta.getMarker()); - break; - } - } - - fireModelChanged(); - } - - /* - * @see AbstractMarkerAnnotationModel#listenToMarkerChanges(boolean) - */ - protected void listenToMarkerChanges(boolean listen) { - if (listen) - fWorkspace.addResourceChangeListener(fResourceChangeListener); - else - fWorkspace.removeResourceChangeListener(fResourceChangeListener); - } - - /* - * @see AbstractMarkerAnnotationModel#deleteMarkers(IMarker[]) - */ - protected void deleteMarkers(final IMarker[] markers) throws CoreException { - fWorkspace.run(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - for (int i= 0; i < markers.length; ++i) { - markers[i].delete(); - } - } - }, null); - } - - /* - * @see AbstractMarkerAnnotationModel#retrieveMarkers() - */ - protected IMarker[] retrieveMarkers() throws CoreException { - return fResource.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO); - } - - /** - * Returns the resource serving as the source of markers for this annotation model. - * - * @return the resource serving as the source of markers for this annotation model - * @since 2.0 - */ - protected IResource getResource() { - return fResource; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RetargetTextEditorAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RetargetTextEditorAction.java deleted file mode 100644 index b408da74032..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RetargetTextEditorAction.java +++ /dev/null @@ -1,149 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; - - -/** - * Action used by an editor action bar contributor to establish placeholders in - * menus or action bars which can be retargeted to dynamically changing actions, - * for example, those which come from the active editor. This action assumes that - * the "wrapped" action sends out property change events in response to state - * changes. It uses these change notification to adapt its enabling state and - * its visual presentation. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - */ -public final class RetargetTextEditorAction extends ResourceAction { - - /** The target action */ - private IAction fAction; - /** The default label if there is no target action */ - private String fDefaultText; - /** The listener to pick up changes of the target action */ - private IPropertyChangeListener fListener= new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - update(event); - } - }; - - /** - * Creates a new action. The action configures its initial visual - * representation from the given resource bundle. If this action's - * wrapped action is set to <code>null</code> it also uses the - * information in the resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @see ResourceAction#ResourceAction - */ - public RetargetTextEditorAction(ResourceBundle bundle, String prefix) { - super(bundle, prefix); - fDefaultText= getText(); - } - - /** - * Creates a new action. The action configures its initial visual - * representation from the given resource bundle. If this action's - * wrapped action is set to <code>null</code> it also uses the - * information in the resource bundle. The action gets the given - * action id. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or <code>null</code> if none - * @param actionId the action id - * @see ResourceAction#ResourceAction - * @since 2.0 - */ - public RetargetTextEditorAction(ResourceBundle bundle, String prefix, String actionId) { - super(bundle, prefix); - fDefaultText= getText(); - setId(actionId); - } - - /** - * Updates to the changes of the underlying action. - * - * @param event the change event describing the state change - */ - private void update(PropertyChangeEvent event) { - if (ENABLED.equals(event.getProperty())) { - Boolean bool= (Boolean) event.getNewValue(); - setEnabled(bool.booleanValue()); - } else if (TEXT.equals(event.getProperty())) - setText((String) event.getNewValue()); - else if (TOOL_TIP_TEXT.equals(event.getProperty())) - setToolTipText((String) event.getNewValue()); - else if (CHECKED.equals(event.getProperty())) { - Boolean bool= (Boolean) event.getNewValue(); - setChecked(bool.booleanValue()); - } - } - - /** - * Sets the underlying action. - * - * @param action the underlying action - */ - public void setAction(IAction action) { - - if (fAction != null) { - fAction.removePropertyChangeListener(fListener); - fAction= null; - } - - fAction= action; - - if (fAction == null) { - - setEnabled(false); - setText(fDefaultText); - setToolTipText(""); //$NON-NLS-1$ - - } else { - - setEnabled(fAction.isEnabled()); - setText(fAction.getText()); - setToolTipText(fAction.getToolTipText()); - fAction.addPropertyChangeListener(fListener); - } - } - - /* - * @see Action#run() - */ - public void run() { - if (fAction != null) - fAction.run(); - } - - /* - * @see IAction#getActionDefinitionId() - * @since 2.0 - */ - public String getActionDefinitionId() { - if(fAction != null) - return fAction.getActionDefinitionId(); - return null; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RevertToSavedAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RevertToSavedAction.java deleted file mode 100644 index 7fe34b01e8e..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/RevertToSavedAction.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.ResourceBundle; - - -/** - * Action for abandoning changes made in the text editor since the last save - * operation. The action is initially associated with a text editor via the - * constructor, but that can be subsequently changed using <code>setEditor</code>. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - */ -public class RevertToSavedAction extends TextEditorAction { - - /** - * Creates a new action for the given text editor. The action configures its - * visual representation from the given resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @see ResourceAction#ResourceAction - */ - public RevertToSavedAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - /* - * @see IAction#run - */ - public void run() { - getTextEditor().doRevertToSaved(); - } - - /* - * @see TextEditorAction#update - */ - public void update() { - setEnabled(getTextEditor().isDirty()); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SaveAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SaveAction.java deleted file mode 100644 index a4e71601cc3..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SaveAction.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import java.util.ResourceBundle; - - -/** - * Action for saving recent changes made in the text editor. The action is - * initially associated with a text editor via the constructor, but that can be - * subsequently changed using <code>setEditor</code>. - * <p> - * This class may be instantiated; it is not intended to be subclassed. - * </p> - */ -public class SaveAction extends TextEditorAction { - - /** - * Creates a new action for the given text editor. The action configures its - * visual representation from the given resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @see ResourceAction#ResourceAction - */ - public SaveAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix, editor); - } - - /* - * @see IAction#run - */ - public void run() { - getTextEditor().getSite().getPage().saveEditor(getTextEditor(), false); - } - - /* - * @see TextEditorAction#update - */ - public void update() { - setEnabled(getTextEditor().isDirty()); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ShiftAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ShiftAction.java deleted file mode 100644 index 7a498afa7ba..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ShiftAction.java +++ /dev/null @@ -1,136 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.text.ITextOperationTarget; - -import org.eclipse.ui.IWorkbenchPartSite; - - - -/** - * Action for shifting code to the right or left by one indentation level. - * @since 2.0 - */ -public final class ShiftAction extends TextEditorAction implements IReadOnlyDependent { - - /** The text operation code */ - private int fOperationCode= -1; - /** The text operation target */ - private ITextOperationTarget fOperationTarget; - - /** - * Creates and initializes the action for the given text editor and operation - * code. The action configures its visual representation from the given resource - * bundle. The action works by asking the text editor at the time for its - * text operation target adapter (using - * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that - * operation with the given opcode. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or <code>null</code> if none - * @param editor the text editor - * @param operationCode the operation code - * @see ResourceAction#ResourceAction - */ - public ShiftAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { - super(bundle, prefix, editor); - fOperationCode= operationCode; - update(); - } - - /** - * The <code>TextOperationAction</code> implementation of this - * <code>IAction</code> method runs the operation with the current - * operation code. - */ - public void run() { - if (fOperationCode != -1 && fOperationTarget != null) { - - ITextEditor editor= getTextEditor(); - if (editor != null) { - - Display display= null; - - IWorkbenchPartSite site= editor.getSite(); - Shell shell= site.getShell(); - if (shell != null && !shell.isDisposed()) - display= shell.getDisplay(); - - BusyIndicator.showWhile(display, new Runnable() { - public void run() { - fOperationTarget.doOperation(fOperationCode); - } - }); - } - } - } - - /* - * @see IUpdate#update() - */ - public void update() { - - ITextEditor editor= getTextEditor(); - if (editor instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) editor; - if (extension.isEditorInputReadOnly()) { - setEnabled(false); - return; - } - } - - if (fOperationTarget == null && editor!= null && fOperationCode != -1) - fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); - - boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); - setEnabled(isEnabled); - } - - /* - * @see TextEditorAction#setEditor(ITextEditor) - */ - public void setEditor(ITextEditor editor) { - super.setEditor(editor); - fOperationTarget= null; - } - - /* - * @see IReadOnlyDependent#isEnabled(boolean) - */ - public boolean isEnabled(boolean isWritable) { - - if (!isWritable) - return false; - - /* - * Note that this implementation still honors the result returned by canDoOperation. - * I.e. if the viewer is set to read-only, this method still returns false. - * It covers the case in which the viewer is also writable. - * - */ - ITextEditor editor= getTextEditor(); - if (fOperationTarget == null && editor!= null && fOperationCode != -1) - fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); - - return (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusLineContributionItem.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusLineContributionItem.java deleted file mode 100644 index 62e8db9506c..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusLineContributionItem.java +++ /dev/null @@ -1,114 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; - -import org.eclipse.jface.action.ContributionItem; - - -/** - * Contribution item for the status line. - * @since 2.0 - */ -public class StatusLineContributionItem extends ContributionItem implements IStatusField { - - /** - * Specific label for the status line. - */ - static class StatusLineLabel extends CLabel { - - /** Left and right margin used in CLabel */ - private static int INDENT= 3; - /** Precomputed label size */ - private Point fFixedSize; - - /** - * Creates a new status line label. - * @param parent parent control - * @param style the swt style bits - */ - public StatusLineLabel(Composite parent, int style) { - super(parent, style); - - GC gc= new GC(parent); - gc.setFont(parent.getFont()); - Point extent= gc.textExtent("MMMMMMMMM"); //$NON-NLS-1$ - gc.dispose(); - - fFixedSize= new Point(extent.x + INDENT * 2, 10); - } - - /* - * @see Control#computeSize(int, int, boolean) - */ - public Point computeSize(int wHint, int hHint, boolean changed) { - return fFixedSize; - } - }; - - /** The label text */ - private String fText; - /** The label image */ - private Image fImage; - /** The status line label widget */ - private StatusLineLabel fLabel; - - /** - * Creates a new item with the given id. - * - * @param id the item's id - */ - public StatusLineContributionItem(String id) { - super(id); - } - - /* - * @see IStatusField#setText - */ - public void setText(String text) { - fText= text; - if (fLabel != null && !fLabel.isDisposed()) { - fLabel.setText(fText); - } - } - - /* - * @see IStatusField#setImage(Image) - */ - public void setImage(Image image) { - fImage= image; - if (fLabel != null && !fLabel.isDisposed()) { - fLabel.setImage(fImage); - } - } - - /* - * @see IContributionItem#fill(Composite) - */ - public void fill(Composite parent) { - fLabel= new StatusLineLabel(parent, SWT.SHADOW_IN); - fLabel.setData(this); - - if (fText != null) - fLabel.setText(fText); - } -} - diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusTextEditor.java deleted file mode 100644 index e4e8358bf46..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/StatusTextEditor.java +++ /dev/null @@ -1,184 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; - -import org.eclipse.ui.IEditorInput; - - -/** - * Capable of handling input elements that have an associated status with them. - * @since 2.0 - */ -public class StatusTextEditor extends AbstractTextEditor { - - /** The root composite of this editor */ - private Composite fParent; - /** The layout used to manage the regular and the status page */ - private StackLayout fStackLayout; - /** The root composite for the regular page */ - private Composite fDefaultComposite; - /** The status page */ - private Control fStatusControl; - - /* - * @see IWorkbenchPart#createPartControl(Composite) - */ - public void createPartControl(Composite parent) { - - fParent= new Composite(parent, SWT.NONE); - fStackLayout= new StackLayout(); - fParent.setLayout(fStackLayout); - - fDefaultComposite= new Composite(fParent, SWT.NONE); - fDefaultComposite.setLayout(new FillLayout()); - super.createPartControl(fDefaultComposite); - - updatePartControl(getEditorInput()); - } - - /** - * Checks if the status of the given input is OK. If not the - * status control is shown rather than the default control. - * - * @param input the input whose status is checked - */ - public void updatePartControl(IEditorInput input) { - - if (fStatusControl != null) { - fStatusControl.dispose(); - fStatusControl= null; - } - - Control front= null; - if (fParent != null && input != null) { - if (getDocumentProvider() instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) getDocumentProvider(); - IStatus status= extension.getStatus(input); - if (status.isOK()) { - front= fDefaultComposite; - } else { - fStatusControl= createStatusControl(fParent, status); - front= fStatusControl; - } - } - } - - if (fStackLayout.topControl != front) { - fStackLayout.topControl= front; - fParent.layout(); - updateStatusFields(); - } - } - - /** - * Creates the status control for the given status. May be overridden by subclasses. - * - * @param parent the parent control - * @param status the status - */ - protected Control createStatusControl(Composite parent, IStatus status) { - InfoForm infoForm= new InfoForm(parent); - infoForm.setHeaderText(getStatusHeader(status)); - infoForm.setBannerText(getStatusBanner(status)); - infoForm.setInfo(getStatusMessage(status)); - return infoForm.getControl(); - } - - /** - * Returns a header for the given status - * - * @param status the status whose message is returned - * @return a header for the given status - */ - protected String getStatusHeader(IStatus status) { - return ""; //$NON-NLS-1$ - } - - /** - * Returns a banner for the given status. - * - * @param status the status whose message is returned - * @return a banner for the given status - */ - protected String getStatusBanner(IStatus status) { - return ""; //$NON-NLS-1$ - } - - /** - * Returns a message for the given status. - * - * @param status the status whose message is returned - * @return a message for the given status - */ - protected String getStatusMessage(IStatus status) { - return status.getMessage(); - } - - /* - * @see AbstractTextEditor#updateStatusField(String) - */ - protected void updateStatusField(String category) { - IDocumentProvider provider= getDocumentProvider(); - if (provider instanceof IDocumentProviderExtension) { - IDocumentProviderExtension extension= (IDocumentProviderExtension) provider; - IStatus status= extension.getStatus(getEditorInput()); - if (status != null && !status.isOK()) { - IStatusField field= getStatusField(category); - if (field != null) { - field.setText(fErrorLabel); - return; - } - } - } - - super.updateStatusField(category); - } - - /* - * @see AbstractTextEditor#doSetInput(IEditorInput) - */ - protected void doSetInput(IEditorInput input) throws CoreException { - super.doSetInput(input); - if (fParent != null && !fParent.isDisposed()) - updatePartControl(getEditorInput()); - } - - /* - * @see ITextEditor#doRevertToSaved() - */ - public void doRevertToSaved() { - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19014 - super.doRevertToSaved(); - if (fParent != null && !fParent.isDisposed()) - updatePartControl(getEditorInput()); - } - - /* - * @see AbstractTextEditor#sanityCheckState(IEditorInput) - */ - protected void sanityCheckState(IEditorInput input) { - // http://dev.eclipse.org/bugs/show_bug.cgi?id=19014 - super.sanityCheckState(input); - if (fParent != null && !fParent.isDisposed()) - updatePartControl(getEditorInput()); - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextEditorAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextEditorAction.java deleted file mode 100644 index 09e8db7faaf..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextEditorAction.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ResourceBundle; - -/** - * Sekelleton of a standard text editor action. The action is - * initially associated with a text editor via the constructor, - * but can subsequently be changed using <code>setEditor</code>. - * Subclasses must implement the <code>run</code> method and if - * required override the <code>update</code> method. - * </p> - */ -public abstract class TextEditorAction extends ResourceAction implements IUpdate { - - /** The action's editor */ - private ITextEditor fTextEditor; - - /** - * Creates and initializes the action for the given text editor. The action - * configures its visual representation from the given resource bundle. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @see ResourceAction#ResourceAction - */ - protected TextEditorAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - super(bundle, prefix); - setEditor(editor); - update(); - } - - /** - * Returns the action's text editor. - * - * @return the action's text editor - */ - protected ITextEditor getTextEditor() { - return fTextEditor; - } - - /** - * Retargets this action to the given editor. - * - * @param editor the new editor, or <code>null</code> if none - */ - public void setEditor(ITextEditor editor) { - fTextEditor= editor; - } - - /** - * Always enables this action if it is connected to a text editor. - * If the asocciated editor is <code>null</code>, the action is disabled. - * Subclasses may override. - */ - public void update() { - setEnabled(getTextEditor() != null); - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextNavigationAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextNavigationAction.java deleted file mode 100644 index 499f537029d..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextNavigationAction.java +++ /dev/null @@ -1,258 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuCreator; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.HelpListener; -import org.eclipse.swt.widgets.Event; - - -/** - * An <code>IAction</code> wrapper for text widget navigational and selection actions. - * @since 2.0 - */ -public class TextNavigationAction implements IAction { - - /** The text widget */ - private StyledText fTextWidget; - /** The styled text action id */ - private int fAction; - /** The action's action id */ - private String fActionId; - /** This action's action definition id */ - private String fActionDefinitionId; - - - /** - * Creates a new <code>TextNavigationAction</code>. - * @param textWidget the text widget - * @param action the styled text widget action - */ - public TextNavigationAction(StyledText textWidget, int action) { - fTextWidget= textWidget; - fAction= action; - } - - /* - * @see IAction#run() - */ - public void run() { - fTextWidget.invokeAction(fAction); - } - - /* - * @see IAction#runWithEvent(Event) - */ - public void runWithEvent(Event event) { - run(); - } - - /* - * @see IAction#setActionDefinitionId(String) - */ - public void setActionDefinitionId(String id) { - fActionDefinitionId= id; - } - - /* - * @see IAction#getActionDefinitionId() - */ - public String getActionDefinitionId() { - return fActionDefinitionId; - } - - /* - * @see IAction#setId(String) - */ - public void setId(String id) { - fActionId= id; - } - - /* - * @see IAction#getId() - */ - public String getId() { - return fActionId; - } - - -// ---------------------------------------------------------------------------------------------------------------------------------- -// All the subsequent methods are just empty method bodies. - - /* - * @see IAction#addPropertyChangeListener(IPropertyChangeListener) - */ - public void addPropertyChangeListener(IPropertyChangeListener listener) { - } - - /* - * @see IAction#getAccelerator() - */ - public int getAccelerator() { - return 0; - } - - /* - * @see IAction#getDescription() - */ - public String getDescription() { - return null; - } - - /* - * @see IAction#getDisabledImageDescriptor() - */ - public ImageDescriptor getDisabledImageDescriptor() { - return null; - } - - /* - * @see IAction#getHelpListener() - */ - public HelpListener getHelpListener() { - return null; - } - - /* - * @see IAction#getHoverImageDescriptor() - */ - public ImageDescriptor getHoverImageDescriptor() { - return null; - } - - /* - * @see IAction#getImageDescriptor() - */ - public ImageDescriptor getImageDescriptor() { - return null; - } - - /* - * @see IAction#getMenuCreator() - */ - public IMenuCreator getMenuCreator() { - return null; - } - - /* - * @see IAction#getStyle() - */ - public int getStyle() { - return 0; - } - - /* - * @see IAction#getText() - */ - public String getText() { - return null; - } - - /* - * @see IAction#getToolTipText() - */ - public String getToolTipText() { - return null; - } - - /* - * @see IAction#isChecked() - */ - public boolean isChecked() { - return false; - } - - /* - * @see IAction#isEnabled() - */ - public boolean isEnabled() { - return true; - } - - /* - * @see IAction#removePropertyChangeListener(IPropertyChangeListener) - */ - public void removePropertyChangeListener(IPropertyChangeListener listener) { - } - - /* - * @see IAction#setAccelerator(int) - */ - public void setAccelerator(int keycode) { - } - - /* - * @see IAction#setChecked(boolean) - */ - public void setChecked(boolean checked) { - } - - /* - * @see IAction#setDescription(String) - */ - public void setDescription(String text) { - } - - /* - * @see IAction#setDisabledImageDescriptor(ImageDescriptor) - */ - public void setDisabledImageDescriptor(ImageDescriptor newImage) { - } - - /* - * @see IAction#setEnabled(boolean) - */ - public void setEnabled(boolean enabled) { - } - - /* - * @see IAction#setHelpListener(HelpListener) - */ - public void setHelpListener(HelpListener listener) { - } - - /* - * @see IAction#setHoverImageDescriptor(ImageDescriptor) - */ - public void setHoverImageDescriptor(ImageDescriptor newImage) { - } - - /* - * @see IAction#setImageDescriptor(ImageDescriptor) - */ - public void setImageDescriptor(ImageDescriptor newImage) { - } - - /* - * @see IAction#setMenuCreator(IMenuCreator) - */ - public void setMenuCreator(IMenuCreator creator) { - } - - /* - * @see IAction#setText(String) - */ - public void setText(String text) { - } - - /* - * @see IAction#setToolTipText(String) - */ - public void setToolTipText(String text) { - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextOperationAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextOperationAction.java deleted file mode 100644 index 462f123abf7..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextOperationAction.java +++ /dev/null @@ -1,157 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import java.util.ResourceBundle; - -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import org.eclipse.jface.text.ITextOperationTarget; - -import org.eclipse.ui.IWorkbenchPartSite; - - -/** - * An action which gets a text operation target from its text editor. - * <p> - * The action is initially associated with a text editor via the constructor, - * but can subsequently be changed using <code>setEditor</code>. - * </p> - * <p> - * If this class is used as is, it works by asking the text editor for its - * text operation target adapter (using <code>getAdapter(ITextOperationTarget.class)</code>. - * The action runs this operation with the pre-configured opcode. - * </p> - */ -public final class TextOperationAction extends TextEditorAction { - - /** The text operation code */ - private int fOperationCode= -1; - /** The text operation target */ - private ITextOperationTarget fOperationTarget; - /** - * Indicates whether this action can be executed on read only editors - * @since 2.0 - */ - private boolean fRunsOnReadOnly= false; - - /** - * Creates and initializes the action for the given text editor and operation - * code. The action configures its visual representation from the given resource - * bundle. The action works by asking the text editor at the time for its - * text operation target adapter (using - * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that - * operation with the given opcode. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @param operationCode the operation code - * @see ResourceAction#ResourceAction - */ - public TextOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) { - super(bundle, prefix, editor); - fOperationCode= operationCode; - update(); - } - - /** - * Creates and initializes the action for the given text editor and operation - * code. The action configures its visual representation from the given resource - * bundle. The action works by asking the text editor at the time for its - * text operation target adapter (using - * <code>getAdapter(ITextOperationTarget.class)</code>. The action runs that - * operation with the given opcode. - * - * @param bundle the resource bundle - * @param prefix a prefix to be prepended to the various resource keys - * (described in <code>ResourceAction</code> constructor), or - * <code>null</code> if none - * @param editor the text editor - * @param operationCode the operation code - * @param runsOnReadOnly <code>true</code> if action can be executed on read-only files - * - * @see ResourceAction#ResourceAction - * @since 2.0 - */ - public TextOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode, boolean runsOnReadOnly) { - super(bundle, prefix, editor); - fOperationCode= operationCode; - fRunsOnReadOnly= runsOnReadOnly; - update(); - } - - /** - * The <code>TextOperationAction</code> implementation of this - * <code>IAction</code> method runs the operation with the current - * operation code. - */ - public void run() { - if (fOperationCode != -1 && fOperationTarget != null) { - - ITextEditor editor= getTextEditor(); - if (editor != null) { - - Display display= null; - - IWorkbenchPartSite site= editor.getSite(); - Shell shell= site.getShell(); - if (shell != null && !shell.isDisposed()) - display= shell.getDisplay(); - - BusyIndicator.showWhile(display, new Runnable() { - public void run() { - fOperationTarget.doOperation(fOperationCode); - } - }); - } - } - } - - /** - * The <code>TextOperationAction</code> implementation of this - * <code>IUpdate</code> method discovers the operation through the current - * editor's <code>ITextOperationTarget</code> adapter, and sets the - * enabled state accordingly. - */ - public void update() { - - ITextEditor editor= getTextEditor(); - if (editor instanceof ITextEditorExtension) { - ITextEditorExtension extension= (ITextEditorExtension) editor; - if (extension.isEditorInputReadOnly() && !fRunsOnReadOnly) { - setEnabled(false); - return; - } - } - - if (fOperationTarget == null && editor!= null && fOperationCode != -1) - fOperationTarget= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); - - boolean isEnabled= (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode)); - setEnabled(isEnabled); - } - - /* - * @see TextEditorAction#setEditor(ITextEditor) - */ - public void setEditor(ITextEditor editor) { - super.setEditor(editor); - fOperationTarget= null; - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextSelectionNavigationLocation.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextSelectionNavigationLocation.java deleted file mode 100644 index 265372cea64..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextSelectionNavigationLocation.java +++ /dev/null @@ -1,273 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - -package org.eclipse.ui.texteditor; - -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.ITextSelection; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; - -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.INavigationLocation; -import org.eclipse.ui.NavigationLocation; - -import org.eclipse.ui.internal.IWorkbenchConstants; - - -/** - * 2.1 - WORK_IN_PROGRESS do not use. - */ -public class TextSelectionNavigationLocation extends NavigationLocation { - - - private final static String DELETED= "deleted"; - private final static String NOT_DELETED= "not_deleted"; - - private final static String CATEGORY= "__navigation_" + TextSelectionNavigationLocation.class.hashCode(); - private static IPositionUpdater fgPositionUpdater= new DefaultPositionUpdater(CATEGORY); - - private Position fPosition; - private IDocument fDocument; - private Position fSavedPosition; - - - public TextSelectionNavigationLocation(ITextEditor part,boolean initialize) { - super(part); - if(!initialize) - return; - - ISelection s= part.getSelectionProvider().getSelection(); - //TBD: AbstractTextEditor doGetSelection may return null but the API getSelection() - //does not specify that it can return null. Shouldn't it return an empty selection - //instead? - - IDocument document= getDocument(part); - if(s == null) - return; - - ITextSelection selection= (ITextSelection) s; - if(selection.getOffset() == 0 && selection.getLength() == 0) - return; - - Position position= new Position(selection.getOffset(), selection.getLength()); - if (installOnDocument(document, position)) { - fDocument= document; - fPosition= position; - - if (!part.isDirty()) - fSavedPosition= new Position(fPosition.offset, fPosition.length); - } - } - - private IDocument getDocument(ITextEditor part) { - IDocumentProvider provider= part.getDocumentProvider(); - return provider.getDocument(part.getEditorInput()); - } - - private boolean installOnDocument(IDocument document, Position position) { - - if (document != null && position != null) { - - if (!document.containsPositionCategory(CATEGORY)) { - document.addPositionCategory(CATEGORY); - document.addPositionUpdater(fgPositionUpdater); - } - - try { - document.addPosition(CATEGORY, position); - return true; - } catch (BadLocationException e) { - } catch (BadPositionCategoryException e) { - } - } - - return false; - } - - private boolean uninstallFromDocument(IDocument document, Position position) { - - if (document != null && position != null) { - try { - - document.removePosition(CATEGORY, position); - - Position[] category= document.getPositions(CATEGORY); - if (category == null || category.length == 0) { - document.removePositionCategory(CATEGORY); - document.removePositionUpdater(fgPositionUpdater); - } - return true; - - } catch (BadPositionCategoryException e) { - } - } - - return false; - } - - public String toString() { - return "Selection<" + fPosition + ">"; - } - - private boolean equalsLocationOf(IEditorPart part) { - - if (fPosition == null) - return true; - - if (fPosition.isDeleted) - return false; - - ISelectionProvider provider= part.getSite().getSelectionProvider(); - ISelection selection= provider.getSelection(); - if (selection instanceof ITextSelection) { - ITextSelection textSelection= (ITextSelection) selection; - if (textSelection.getOffset() == fPosition.offset && textSelection.getLength() == fPosition.length) { - String text= textSelection.getText(); - if (text != null) { - try { - return text.equals(fDocument.get(fPosition.offset, fPosition.length)); - } catch (BadLocationException e) { - } - } - } - } - - return false; - } - - public void dispose() { - uninstallFromDocument(fDocument, fPosition); - fDocument= null; - fPosition= null; - fSavedPosition= null; - super.dispose(); - } - - public void releaseState() { - // deactivate - uninstallFromDocument(fDocument, fPosition); - fDocument= null; - fPosition= null; - fSavedPosition= null; - super.releaseState(); - } - - public boolean mergeInto(INavigationLocation location) { - - if (location == null) - return false; - - if (getClass() != location.getClass()) - return false; - - TextSelectionNavigationLocation s= (TextSelectionNavigationLocation) location; - - if (fPosition == null || fPosition.isDeleted) - return true; - - if (s.fPosition == null || s.fPosition.isDeleted) { - uninstallFromDocument(fDocument, fPosition); - s.fDocument= fDocument; - s. fPosition= fPosition; - s.fSavedPosition= fSavedPosition; - return true; - } - - return s.fDocument == fDocument && s.fPosition.equals(fPosition); - } - - public void restoreLocation() { - if (fPosition == null || fPosition.isDeleted) - return; - - if (getEditorPart() instanceof ITextEditor) { - ITextEditor editor= (ITextEditor) getEditorPart(); - editor.selectAndReveal(fPosition.offset, fPosition.length); - } - } - - public void restoreState(IMemento memento) { - - IEditorPart part= getEditorPart(); - if (part instanceof ITextEditor) { - - // restore - fDocument= getDocument((ITextEditor) part); - - Integer offset= memento.getInteger(IWorkbenchConstants.TAG_X); - Integer length= memento.getInteger(IWorkbenchConstants.TAG_Y); - String deleted= memento.getString(IWorkbenchConstants.TAG_INFO); - - if (offset != null && length != null) { - fPosition= new Position(offset.intValue(), length.intValue()); - if (deleted != null) - fPosition.isDeleted= DELETED.equals(deleted) ? true : false; - } - - // activate - if (installOnDocument(fDocument, fPosition) && !part.isDirty()) - fSavedPosition= new Position(fPosition.offset, fPosition.length); - } - } - - public void saveState(IMemento memento) { - - // save - if (fSavedPosition != null) { - memento.putInteger(IWorkbenchConstants.TAG_X, fSavedPosition.offset); - memento.putInteger(IWorkbenchConstants.TAG_Y, fSavedPosition.length); - memento.putString(IWorkbenchConstants.TAG_INFO, (fSavedPosition.isDeleted ? DELETED : NOT_DELETED)); - } - } - - public void partSaved(IEditorPart part) { - - if (fPosition == null) - return; - - if (fSavedPosition == null) - fSavedPosition= new Position(0, 0); - - fSavedPosition.offset= fPosition.offset; - fSavedPosition.length= fPosition.length; - fSavedPosition.isDeleted= fPosition.isDeleted; - } - public void update() { - ITextEditor part = (ITextEditor)getEditorPart(); - if(equalsLocationOf(part)) - return; - - uninstallFromDocument(fDocument,fPosition); - ISelection s= part.getSelectionProvider().getSelection(); - if(s == null) - return; - - ITextSelection selection= (ITextSelection) s; - if(selection.getOffset() == 0 && selection.getLength() == 0) - return; - - Position position= new Position(selection.getOffset(), selection.getLength()); - if (installOnDocument(fDocument, position)) { - fPosition= position; - - if (!part.isDirty()) - fSavedPosition= new Position(fPosition.offset, fPosition.length); - } - - } -} diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextUtilities.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextUtilities.java deleted file mode 100644 index 89651ab3f1c..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/TextUtilities.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.eclipse.ui.texteditor; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * Collection of text functions. - */ -class TextUtilities { - - /* - * 1GF86V3: ITPUI:WINNT - Internal errors using Find/Replace Dialog - * Copied from JFace text - */ - - - public final static String[] fgDelimiters= new String[] { "\n", "\r", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ - - - /** - * Determines which one of fgDelimiters appears first in the list. If none of them the - * hint is returned. - */ - public static String determineLineDelimiter(String text, String hint) { - try { - int[] info= indexOf(fgDelimiters, text, 0); - return fgDelimiters[info[1]]; - } catch (ArrayIndexOutOfBoundsException x) { - } - return hint; - } - - /** - * Returns the position in the string greater than offset - * of the longest matching search string. - */ - public static int[] indexOf(String[] searchStrings, String text, int offset) { - - int[] result= { -1, -1 }; - - for (int i= 0; i < searchStrings.length; i++) { - int index= text.indexOf(searchStrings[i], offset); - if (index >= 0) { - - if (result[0] == -1) { - result[0]= index; - result[1]= i; - } else if (index < result[0]) { - result[0]= index; - result[1]= i; - } else if (index == result[0] && searchStrings[i].length() > searchStrings[result[1]].length()) { - result[0]= index; - result[1]= i; - } - } - } - - return result; - - } - - /** - * Returns the longest search string with which the given text ends. - */ - public static int endsWith(String[] searchStrings, String text) { - - int index= -1; - - for (int i= 0; i < searchStrings.length; i++) { - if (text.endsWith(searchStrings[i])) { - if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) - index= i; - } - } - - return index; - } - - /** - * Returns the longest search string with which the given text starts. - */ - public static int startsWith(String[] searchStrings, String text) { - - int index= -1; - - for (int i= 0; i < searchStrings.length; i++) { - if (text.startsWith(searchStrings[i])) { - if (index == -1 || searchStrings[i].length() > searchStrings[index].length()) - index= i; - } - } - - return index; - } - - /** - * Returns whether the text equals one of the given compare strings. - */ - public static int equals(String[] compareStrings, String text) { - for (int i= 0; i < compareStrings.length; i++) { - if (text.equals(compareStrings[i])) - return i; - } - return -1; - } -}
\ No newline at end of file diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WorkbenchChainedTextFontFieldEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WorkbenchChainedTextFontFieldEditor.java deleted file mode 100644 index f1eafb1c8aa..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/WorkbenchChainedTextFontFieldEditor.java +++ /dev/null @@ -1,70 +0,0 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. 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 implementation -**********************************************************************/ - - -package org.eclipse.ui.texteditor; - - -import org.eclipse.swt.widgets.Composite; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Plugin; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.PropagatingFontFieldEditor; - -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.plugin.AbstractUIPlugin; - - -/** - * This font field editor implements chaining between the workbench's preference - * store and a given target preference store. Any time the workbench's preference - * for the text font changes, the change is propagated to the target store. - * Propagation means that the actual text font stored in the workbench store is set as - * default text font in the target store. If the target store does not contain a value - * rather than the default text font, the new default text font is immediately effective. - * - * @see org.eclipse.jface.preference.FontFieldEditor - * @since 2.0 - */ -public class WorkbenchChainedTextFontFieldEditor extends PropagatingFontFieldEditor { - - /** - * 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 - */ - public WorkbenchChainedTextFontFieldEditor(String name, String labelText, Composite parent) { - super(name, labelText, parent, EditorMessages.getString("WorkbenchChainedTextFontFieldEditor.defaultWorkbenchTextFont")); //$NON-NLS-1$ - } - - /** - * Starts the propagation of the text font preference set in the workbench - * to given target preference store using the given preference key. - * - * @param target the target preference store - * @param targetKey the key to be used in the target preference store - */ - public static void startPropagate(IPreferenceStore target, String targetKey) { - Plugin plugin= Platform.getPlugin(PlatformUI.PLUGIN_ID); - if (plugin instanceof AbstractUIPlugin) { - AbstractUIPlugin uiPlugin= (AbstractUIPlugin) plugin; - IPreferenceStore store= uiPlugin.getPreferenceStore(); - if (store != null) - PropagatingFontFieldEditor.startPropagate(store, JFaceResources.TEXT_FONT, target, targetKey); - } - } -} - diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/package.html b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/package.html deleted file mode 100644 index 0ebf7f2db7f..00000000000 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/package.html +++ /dev/null @@ -1,30 +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 text editors obeying to the -desktop rules. -<h2> -Package Specification</h2> -<tt>ITextEditor</tt> extends <tt>IEditorPart</tt> with text editor specific -functionality. Text editors use source viewers (<tt>ISourceViewer</tt>) -for displaying and editing the given editor input. In order to translate -the editor input into a document and vice versa (e.g., for saving a change), -a text editor uses document providers (<tt>IDocumentProvider</tt>). A document -provider is responsible not just for providing the document for a given -editor input but for the complete translation between the domain model -and the editor's internal document-based model. Document provider can be -shared between editors. -<br>The package provides a default implementation of <tt>ITextEditor</tt> -(<tt>AbstractTextEditor</tt>). This default implementation also covers -the editor's complete action management and activation. The package contains -a number of configurable and predefined actions. <tt>AbstractMarkerAnnotationModel</tt> -establishs a link between text annotations (<tt>Annotation</tt>) and desktop -markers (<tt>IMarker</tt>). -</body> -</html> |