Source Code Cross Referenced for IncrementalFindTarget.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » texteditor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui workbench » org.eclipse.ui.texteditor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *     Felix Pahl (fpahl@web.de) - fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=51820
011:         *******************************************************************************/package org.eclipse.ui.texteditor;
012:
013:        import java.util.Stack;
014:
015:        import org.eclipse.swt.SWT;
016:        import org.eclipse.swt.custom.StyledText;
017:        import org.eclipse.swt.custom.VerifyKeyListener;
018:        import org.eclipse.swt.events.FocusEvent;
019:        import org.eclipse.swt.events.FocusListener;
020:        import org.eclipse.swt.events.MouseEvent;
021:        import org.eclipse.swt.events.MouseListener;
022:        import org.eclipse.swt.events.VerifyEvent;
023:        import org.eclipse.swt.graphics.Color;
024:        import org.eclipse.swt.graphics.Point;
025:
026:        import org.eclipse.core.commands.ExecutionEvent;
027:        import org.eclipse.core.commands.ExecutionException;
028:        import org.eclipse.core.commands.IExecutionListener;
029:        import org.eclipse.core.commands.NotHandledException;
030:
031:        import org.eclipse.core.runtime.Assert;
032:
033:        import org.eclipse.jface.action.IStatusLineManager;
034:        import org.eclipse.jface.viewers.ISelection;
035:        import org.eclipse.jface.viewers.ISelectionChangedListener;
036:        import org.eclipse.jface.viewers.ISelectionProvider;
037:        import org.eclipse.jface.viewers.SelectionChangedEvent;
038:
039:        import org.eclipse.jface.text.IFindReplaceTarget;
040:        import org.eclipse.jface.text.IFindReplaceTargetExtension;
041:        import org.eclipse.jface.text.IRegion;
042:        import org.eclipse.jface.text.ITextListener;
043:        import org.eclipse.jface.text.ITextSelection;
044:        import org.eclipse.jface.text.ITextViewer;
045:        import org.eclipse.jface.text.ITextViewerExtension;
046:        import org.eclipse.jface.text.TextEvent;
047:
048:        import org.eclipse.ui.PlatformUI;
049:        import org.eclipse.ui.commands.ICommandService;
050:        import org.eclipse.ui.internal.texteditor.NLSUtility;
051:
052:        /**
053:         * An incremental find target. Replace is always disabled.
054:         * @since 2.0
055:         */
056:        class IncrementalFindTarget implements  IFindReplaceTarget,
057:                IFindReplaceTargetExtension, VerifyKeyListener, MouseListener,
058:                FocusListener, ISelectionChangedListener, ITextListener,
059:                IExecutionListener {
060:
061:            /** The string representing rendered tab */
062:            private final static String TAB = EditorMessages.Editor_FindIncremental_render_tab;
063:            /**
064:             * The string representing "Reverse Incremental Find"
065:             * @since 3.0
066:             */
067:            private final static String FIELD_NAME = EditorMessages.Editor_FindIncremental_name;
068:            /**
069:             * The string representing "Incremental Find"
070:             * @since 3.0
071:             */
072:            private final static String REVERSE_FIELD_NAME = EditorMessages.Editor_FindIncremental_reverse_name;
073:            /**
074:             * The string representing reverse
075:             * @since 2.1
076:             */
077:            private final static String REVERSE = EditorMessages.Editor_FindIncremental_reverse;
078:            /**
079:             * The string representing wrapped
080:             * @since 2.1
081:             */
082:            private final static String WRAPPED = EditorMessages.Editor_FindIncremental_wrapped;
083:            /** The text viewer to operate on */
084:            private final ITextViewer fTextViewer;
085:            /** The status line manager for output */
086:            private final IStatusLineManager fStatusLine;
087:            /** The find replace target to delegate find requests */
088:            private final IFindReplaceTarget fTarget;
089:            /** The current find string */
090:            private StringBuffer fFindString = new StringBuffer();
091:            /** The position of the first upper case character, -1 if none */
092:            private int fCasePosition;
093:            /**
094:             * The position in the stack of the first wrap search, -1 if none
095:             * @since 2.1
096:             */
097:            private int fWrapPosition;
098:            /** The position of the last successful find */
099:            private int fCurrentIndex;
100:            /** A flag indicating if last find was successful */
101:            private boolean fFound;
102:            /**
103:             * A flag indicating if the last search was forward
104:             * @since 2.1
105:             */
106:            private boolean fForward = true;
107:            /** A flag indicating listeners are installed. */
108:            private boolean fInstalled;
109:            /**
110:             * A flag indicating that a search is currently active.
111:             * Used to ignore selection callbacks generated by the incremental search itself.
112:             * @since 2.1
113:             */
114:            private boolean fSearching;
115:            /** The current find stack */
116:            private Stack fSessionStack;
117:            /**
118:             * The previous search string
119:             * @since 2.1
120:             */
121:            private String fPrevFindString = ""; //$NON-NLS-1$
122:            /**
123:             * The previous position of the first upper case character, -1 if none
124:             * @since 3.0
125:             */
126:            private int fPrevCasePosition = -1;
127:            /**
128:             * The find status field.
129:             * @since 3.0
130:             */
131:            private IStatusField fStatusField;
132:            /**
133:             * Tells whether the status field implements
134:             * <code>IStatusFieldExtension</code>.
135:             * @see IStatusFieldExtension
136:             * @since 3.0
137:             */
138:            private boolean fIsStatusFieldExtension;
139:
140:            /**
141:             * Data structure for a search result.
142:             * @since 2.1
143:             */
144:            private class SearchResult {
145:                int selection, length, index, findLength;
146:                boolean found, forward;
147:
148:                /**
149:                 * Creates a new search result data object and fills
150:                 * it with the current values of this target.
151:                 */
152:                public SearchResult() {
153:                    Point p = fTarget.getSelection();
154:                    selection = p.x;
155:                    length = p.y;
156:                    index = fCurrentIndex;
157:                    findLength = fFindString.length();
158:                    found = fFound;
159:                    forward = fForward;
160:                }
161:
162:            }
163:
164:            /**
165:             * Stores the search result.
166:             */
167:            private void saveState() {
168:                fSessionStack.push(new SearchResult());
169:            }
170:
171:            /**
172:             * Restores the search result.
173:             *
174:             * @since 2.1
175:             */
176:            private void restoreState() {
177:
178:                StyledText text = fTextViewer.getTextWidget();
179:                if (text == null || text.isDisposed())
180:                    return;
181:
182:                SearchResult searchResult = null;
183:                if (!fSessionStack.empty())
184:                    searchResult = (SearchResult) fSessionStack.pop();
185:
186:                if (searchResult == null) {
187:                    text.getDisplay().beep();
188:                    return;
189:                }
190:
191:                text.setSelectionRange(searchResult.selection,
192:                        searchResult.length);
193:                text.showSelection();
194:
195:                // relies on the contents of the StringBuffer
196:                fFindString.setLength(searchResult.findLength);
197:                fCurrentIndex = searchResult.index;
198:                fFound = searchResult.found;
199:                fForward = searchResult.forward;
200:
201:                // Recalculate the indices
202:                if (fFindString.length() <= fCasePosition)
203:                    fCasePosition = -1;
204:                if (fSessionStack.size() < fWrapPosition)
205:                    fWrapPosition = -1;
206:            }
207:
208:            /**
209:             * Sets the direction for the next search.
210:             * This can be called before <code>beginSession</code> to set the initial search direction.
211:             * @param forward <code>true</code> if the next search should be forward
212:             * @see #beginSession()
213:             * @since 2.1
214:             */
215:            public void setDirection(boolean forward) {
216:                fForward = forward;
217:            }
218:
219:            /**
220:             * Creates an instance of an incremental find target.
221:             * @param viewer the text viewer to operate on
222:             * @param manager the status line manager for output
223:             */
224:            public IncrementalFindTarget(ITextViewer viewer,
225:                    IStatusLineManager manager) {
226:                Assert.isNotNull(viewer);
227:                Assert.isNotNull(manager);
228:                fTextViewer = viewer;
229:                fStatusLine = manager;
230:                fTarget = viewer.getFindReplaceTarget();
231:            }
232:
233:            /*
234:             * @see IFindReplaceTarget#canPerformFind()
235:             */
236:            public boolean canPerformFind() {
237:                return fTarget.canPerformFind();
238:            }
239:
240:            /*
241:             * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean)
242:             */
243:            public int findAndSelect(int offset, String findString,
244:                    boolean searchForward, boolean caseSensitive,
245:                    boolean wholeWord) {
246:                return fTarget.findAndSelect(offset, findString, searchForward,
247:                        caseSensitive, wholeWord);
248:            }
249:
250:            /*
251:             * @see IFindReplaceTarget#getSelection()
252:             */
253:            public Point getSelection() {
254:                return fTarget.getSelection();
255:            }
256:
257:            /*
258:             * @see IFindReplaceTarget#getSelectionText()
259:             */
260:            public String getSelectionText() {
261:                return fTarget.getSelectionText();
262:            }
263:
264:            /*
265:             * @see IFindReplaceTarget#isEditable()
266:             */
267:            public boolean isEditable() {
268:                return false;
269:            }
270:
271:            /*
272:             * @see IFindReplaceTarget#replaceSelection(String)
273:             */
274:            public void replaceSelection(String text) {
275:            }
276:
277:            /*
278:             * @see IFindReplaceTargetExtension#beginSession()
279:             */
280:            public void beginSession() {
281:                fSearching = true;
282:
283:                // Workaround since some accelerators get handled directly by the OS
284:                if (fInstalled) {
285:                    saveState();
286:                    repeatSearch(fForward);
287:                    updateStatus();
288:                    fSearching = false;
289:                    return;
290:                }
291:
292:                fFindString.setLength(0);
293:                fSessionStack = new Stack();
294:                fCasePosition = -1;
295:                fWrapPosition = -1;
296:                fFound = true;
297:
298:                // clear initial selection
299:                StyledText text = fTextViewer.getTextWidget();
300:                if (text != null && !text.isDisposed()) {
301:                    fCurrentIndex = text.getCaretOffset();
302:                    text.setSelection(fCurrentIndex);
303:                } else {
304:                    fCurrentIndex = 0;
305:                }
306:
307:                install();
308:
309:                // Set the mark
310:                if (fTextViewer instanceof  ITextViewerExtension)
311:                    ((ITextViewerExtension) fTextViewer).setMark(fCurrentIndex);
312:
313:                updateStatus();
314:
315:                if (fTarget instanceof  IFindReplaceTargetExtension)
316:                    ((IFindReplaceTargetExtension) fTarget).beginSession();
317:
318:                fSearching = false;
319:            }
320:
321:            /*
322:             * @see IFindReplaceTargetExtension#endSession()
323:             */
324:            public void endSession() {
325:                if (fTarget instanceof  IFindReplaceTargetExtension)
326:                    ((IFindReplaceTargetExtension) fTarget).endSession();
327:
328:                // will uninstall itself
329:            }
330:
331:            /*
332:             * @see IFindReplaceTargetExtension#getScope()
333:             */
334:            public IRegion getScope() {
335:                return null;
336:            }
337:
338:            /*
339:             * @see IFindReplaceTargetExtension#setGlobal(boolean)
340:             */
341:            public void setGlobal(boolean global) {
342:            }
343:
344:            /*
345:             * @see IFindReplaceTargetExtension#setScope(IRegion)
346:             */
347:            public void setScope(IRegion scope) {
348:            }
349:
350:            /*
351:             * @see IFindReplaceTargetExtension#setReplaceAllMode(boolean)
352:             */
353:            public void setReplaceAllMode(boolean replaceAll) {
354:            }
355:
356:            /**
357:             * Installs this target. I.e. adds all required listeners.
358:             */
359:            private void install() {
360:
361:                if (fInstalled)
362:                    return;
363:
364:                StyledText text = fTextViewer.getTextWidget();
365:                if (text == null)
366:                    return;
367:
368:                text.addMouseListener(this );
369:                text.addFocusListener(this );
370:                fTextViewer.addTextListener(this );
371:
372:                ISelectionProvider selectionProvider = fTextViewer
373:                        .getSelectionProvider();
374:                if (selectionProvider != null)
375:                    selectionProvider.addSelectionChangedListener(this );
376:
377:                if (fTextViewer instanceof  ITextViewerExtension)
378:                    ((ITextViewerExtension) fTextViewer)
379:                            .prependVerifyKeyListener(this );
380:                else
381:                    text.addVerifyKeyListener(this );
382:
383:                ICommandService commandService = (ICommandService) PlatformUI
384:                        .getWorkbench().getAdapter(ICommandService.class);
385:                if (commandService != null)
386:                    commandService.addExecutionListener(this );
387:
388:                fInstalled = true;
389:            }
390:
391:            /**
392:             * Uninstalls itself. I.e. removes all listeners installed in <code>install</code>.
393:             */
394:            private void uninstall() {
395:
396:                fTextViewer.removeTextListener(this );
397:
398:                ISelectionProvider selectionProvider = fTextViewer
399:                        .getSelectionProvider();
400:                if (selectionProvider != null)
401:                    selectionProvider.removeSelectionChangedListener(this );
402:
403:                StyledText text = fTextViewer.getTextWidget();
404:                if (text != null) {
405:                    text.removeMouseListener(this );
406:                    text.removeFocusListener(this );
407:                }
408:
409:                if (fTextViewer instanceof  ITextViewerExtension) {
410:                    ((ITextViewerExtension) fTextViewer)
411:                            .removeVerifyKeyListener(this );
412:
413:                } else {
414:                    if (text != null)
415:                        text.removeVerifyKeyListener(this );
416:                }
417:
418:                ICommandService commandService = (ICommandService) PlatformUI
419:                        .getWorkbench().getAdapter(ICommandService.class);
420:                if (commandService != null)
421:                    commandService.removeExecutionListener(this );
422:
423:                fInstalled = false;
424:            }
425:
426:            /**
427:             * Updates the status line.
428:             * @since 2.1
429:             */
430:            private void updateStatus() {
431:
432:                if (!fInstalled)
433:                    return;
434:
435:                String string = fFindString.toString();
436:                String wrapPrefix = fWrapPosition == -1 ? "" : WRAPPED; //$NON-NLS-1$
437:                String reversePrefix = fForward ? "" : REVERSE; //$NON-NLS-1$
438:
439:                if (!fFound) {
440:                    String pattern = EditorMessages.Editor_FindIncremental_not_found_pattern;
441:                    statusError(NLSUtility.format(pattern, new Object[] {
442:                            reversePrefix, wrapPrefix, string }));
443:
444:                } else if (string.length() == 0) {
445:                    if (fForward)
446:                        statusMessage(FIELD_NAME);
447:                    else
448:                        statusMessage(REVERSE_FIELD_NAME);
449:                } else if (!fForward || fWrapPosition > -1) {
450:                    String pattern = EditorMessages.Editor_FindIncremental_found_pattern;
451:                    statusMessage(NLSUtility.format(pattern, new Object[] {
452:                            reversePrefix, wrapPrefix, string }));
453:                } else {
454:                    statusMessage(string);
455:                }
456:            }
457:
458:            /*
459:             * @see VerifyKeyListener#verifyKey(VerifyEvent)
460:             */
461:            public void verifyKey(VerifyEvent event) {
462:
463:                if (!event.doit)
464:                    return;
465:
466:                fSearching = true;
467:                if (event.character == 0) {
468:
469:                    switch (event.keyCode) {
470:
471:                    // ALT, CTRL, ARROW_LEFT, ARROW_RIGHT == leave
472:                    case SWT.ARROW_LEFT:
473:                    case SWT.ARROW_RIGHT:
474:                    case SWT.HOME:
475:                    case SWT.END:
476:                    case SWT.PAGE_DOWN:
477:                    case SWT.PAGE_UP:
478:                        leave();
479:                        break;
480:
481:                    case SWT.ARROW_DOWN:
482:                        saveState();
483:                        setDirection(true);
484:                        repeatSearch(fForward);
485:                        event.doit = false;
486:                        break;
487:
488:                    case SWT.ARROW_UP:
489:                        saveState();
490:                        setDirection(false);
491:                        repeatSearch(fForward);
492:                        event.doit = false;
493:                        break;
494:                    }
495:
496:                    // event.character != 0
497:                } else {
498:
499:                    switch (event.character) {
500:
501:                    // ESC, CR = quit
502:                    case 0x1B:
503:                    case 0x0D:
504:                        leave();
505:                        event.doit = false;
506:                        break;
507:
508:                    // backspace	and delete
509:                    case 0x08:
510:                    case 0x7F:
511:                        restoreState();
512:                        event.doit = false;
513:                        break;
514:
515:                    default:
516:                        if (event.stateMask == 0
517:                                || event.stateMask == SWT.SHIFT
518:                                || event.stateMask == (SWT.ALT | SWT.CTRL)) { // SWT.ALT | SWT.CTRL covers AltGr (see bug 43049)
519:                            saveState();
520:                            addCharSearch(event.character);
521:                            event.doit = false;
522:                        }
523:                        break;
524:                    }
525:                }
526:                updateStatus();
527:                fSearching = false;
528:            }
529:
530:            /**
531:             * Repeats the last search while possibly changing the direction.
532:             *
533:             * @param forward <code>true</code> iff the next search should be forward
534:             * @return if the search was successful
535:             * @since 2.1
536:             */
537:            private boolean repeatSearch(boolean forward) {
538:                if (fFindString.length() == 0) {
539:                    fFindString = new StringBuffer(fPrevFindString);
540:                    fCasePosition = fPrevCasePosition;
541:                }
542:
543:                String string = fFindString.toString();
544:                if (string.length() == 0) {
545:                    fFound = true;
546:                    return true;
547:                }
548:
549:                StyledText text = fTextViewer.getTextWidget();
550:                // Cannot use fTarget.getSelection since that does not return which side of the
551:                // selection the caret is on.
552:                int startIndex = text.getCaretOffset();
553:                if (!forward)
554:                    startIndex -= 1;
555:
556:                // Check to see if a wrap is necessary
557:                if (!fFound && (fForward == forward)) {
558:                    startIndex = -1;
559:                    if (fWrapPosition == -1)
560:                        fWrapPosition = fSessionStack.size();
561:                }
562:                fForward = forward;
563:
564:                // Find the string
565:                text.setRedraw(false);
566:                int index = fTarget.findAndSelect(startIndex, string, fForward,
567:                        fCasePosition != -1, false);
568:
569:                // Set the caret on the left if the search is reversed
570:                if (!forward) {
571:                    Point p = fTarget.getSelection();
572:                    text.setSelectionRange(p.x + p.y, -p.y);
573:                    p = null;
574:                }
575:                text.setRedraw(true);
576:
577:                // Take appropriate action
578:                boolean found = (index != -1);
579:                if (!found && fFound) {
580:                    text = fTextViewer.getTextWidget();
581:                    if (text != null && !text.isDisposed())
582:                        text.getDisplay().beep();
583:                }
584:
585:                if (found)
586:                    fCurrentIndex = startIndex;
587:
588:                fFound = found;
589:                return found;
590:            }
591:
592:            /**
593:             * Adds the given character to the search string and repeats the search with the last parameters.
594:             *
595:             * @param c the character to append to the search pattern
596:             * @return <code>true</code> the search found a match
597:             * @since 2.1
598:             */
599:            private boolean addCharSearch(char c) {
600:                // Add char to pattern
601:                if (fCasePosition == -1 && Character.isUpperCase(c)
602:                        && Character.toLowerCase(c) != c)
603:                    fCasePosition = fFindString.length();
604:
605:                fFindString.append(c);
606:                String string = fFindString.toString();
607:                StyledText text = fTextViewer.getTextWidget();
608:
609:                text.setRedraw(false);
610:                int index = fTarget.findAndSelect(fCurrentIndex, string,
611:                        fForward, fCasePosition != -1, false);
612:
613:                // Set the caret on the left if the search is reversed
614:                if (!fForward) {
615:                    Point p = fTarget.getSelection();
616:                    text.setSelectionRange(p.x + p.y, -p.y);
617:                }
618:                text.setRedraw(true);
619:
620:                // Take appropriate action
621:                boolean found = (index != -1);
622:                if (!found && fFound) {
623:                    text = fTextViewer.getTextWidget();
624:                    if (text != null && !text.isDisposed())
625:                        text.getDisplay().beep();
626:                }
627:
628:                fFound = found;
629:                return found;
630:            }
631:
632:            /**
633:             * Leaves this incremental search session.
634:             */
635:            private void leave() {
636:                if (fFindString.length() != 0) {
637:                    fPrevFindString = fFindString.toString();
638:                    fPrevCasePosition = fCasePosition;
639:                }
640:                statusClear();
641:                uninstall();
642:                fSessionStack = null;
643:            }
644:
645:            /*
646:             * @see ITextListener#textChanged(TextEvent)
647:             */
648:            public void textChanged(TextEvent event) {
649:                if (event.getDocumentEvent() != null)
650:                    leave();
651:            }
652:
653:            /*
654:             * @see MouseListener##mouseDoubleClick(MouseEvent)
655:             */
656:            public void mouseDoubleClick(MouseEvent e) {
657:                leave();
658:            }
659:
660:            /*
661:             * @see MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
662:             */
663:            public void mouseDown(MouseEvent e) {
664:                leave();
665:            }
666:
667:            /*
668:             * @see MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
669:             */
670:            public void mouseUp(MouseEvent e) {
671:                leave();
672:            }
673:
674:            /*
675:             * @see FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
676:             */
677:            public void focusGained(FocusEvent e) {
678:                leave();
679:            }
680:
681:            /*
682:             * @see FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
683:             */
684:            public void focusLost(FocusEvent e) {
685:                leave();
686:            }
687:
688:            /**
689:             * Sets the given string as status message, clears the status error message.
690:             * @param string the status message
691:             */
692:            private void statusMessage(String string) {
693:                if (fStatusField != null) {
694:                    if (fIsStatusFieldExtension) {
695:                        ((IStatusFieldExtension) fStatusField)
696:                                .setErrorText(null);
697:                        fStatusField.setText(escapeTabs(string));
698:                        ((IStatusFieldExtension) fStatusField).setVisible(true);
699:                        fStatusLine.update(true);
700:                    } else {
701:                        fStatusLine.setErrorMessage(null);
702:                        fStatusField.setText(escapeTabs(string));
703:                    }
704:                } else {
705:                    fStatusLine.setErrorMessage(null);
706:                    fStatusLine.setMessage(escapeTabs(string));
707:                }
708:            }
709:
710:            /**
711:             * Sets the status error message, clears the status message.
712:             * @param string the status error message
713:             */
714:            private void statusError(String string) {
715:                if (fStatusField != null) {
716:                    if (fIsStatusFieldExtension) {
717:                        ((IStatusFieldExtension) fStatusField)
718:                                .setErrorText(escapeTabs(string));
719:                        fStatusField.setText(""); //$NON-NLS-1$
720:                        ((IStatusFieldExtension) fStatusField).setVisible(true);
721:                        fStatusLine.update(true);
722:                    } else {
723:                        fStatusLine.setErrorMessage(escapeTabs(string));
724:                        fStatusField.setText(""); //$NON-NLS-1$
725:                    }
726:                } else {
727:                    fStatusLine.setErrorMessage(escapeTabs(string));
728:                    fStatusLine.setMessage(null);
729:                }
730:            }
731:
732:            /**
733:             * Clears the status message and the status error message.
734:             */
735:            private void statusClear() {
736:                if (fStatusField != null) {
737:                    if (fIsStatusFieldExtension) {
738:                        fStatusField.setText(""); //$NON-NLS-1$
739:                        ((IStatusFieldExtension) fStatusField)
740:                                .setErrorText(null);
741:                        ((IStatusFieldExtension) fStatusField)
742:                                .setVisible(false);
743:                        fStatusLine.update(true);
744:                    } else {
745:                        fStatusField.setText(""); //$NON-NLS-1$
746:                        fStatusLine.setErrorMessage(null);
747:                    }
748:                } else {
749:                    fStatusLine.setErrorMessage(null);
750:                    fStatusLine.setMessage(null);
751:                }
752:            }
753:
754:            /**
755:             * Translates all tab characters into a proper status line presentation.
756:             * @param string the string in which to translate the tabs
757:             * @return the given string with all tab characters replace with a proper status line presentation
758:             */
759:            private String escapeTabs(String string) {
760:                StringBuffer buffer = new StringBuffer();
761:
762:                int begin = 0;
763:                int end = string.indexOf('\t', begin);
764:
765:                while (end >= 0) {
766:                    buffer.append(string.substring(begin, end));
767:                    buffer.append(TAB);
768:                    begin = end + 1;
769:                    end = string.indexOf('\t', begin);
770:                }
771:                buffer.append(string.substring(begin));
772:
773:                return buffer.toString();
774:            }
775:
776:            /*
777:             * @see IFindReplaceTargetExtension#getLineSelection()
778:             */
779:            public Point getLineSelection() {
780:                if (fTarget instanceof  IFindReplaceTargetExtension)
781:                    return ((IFindReplaceTargetExtension) fTarget)
782:                            .getLineSelection();
783:
784:                return null; // XXX should not return null
785:            }
786:
787:            /*
788:             * @see IFindReplaceTargetExtension#setSelection(int, int)
789:             */
790:            public void setSelection(int offset, int length) {
791:                if (fTarget instanceof  IFindReplaceTargetExtension)
792:                    ((IFindReplaceTargetExtension) fTarget).setSelection(
793:                            offset, length);
794:            }
795:
796:            /*
797:             * @see IFindReplaceTargetExtension#setScopeHighlightColor(Color)
798:             */
799:            public void setScopeHighlightColor(Color color) {
800:            }
801:
802:            /*
803:             * @see ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
804:             * @since 2.1
805:             */
806:            public void selectionChanged(SelectionChangedEvent e) {
807:                boolean ignore = false;
808:                ISelection selection = e.getSelection();
809:                if (selection instanceof  ITextSelection) {
810:                    ITextSelection textSelection = (ITextSelection) selection;
811:                    Point range = getSelection();
812:                    ignore = textSelection.getOffset()
813:                            + textSelection.getLength() == range.x + range.y;
814:                }
815:                if (!fSearching && !ignore)
816:                    leave();
817:            }
818:
819:            /**
820:             * Sets the find status field for this incremental find target.
821:             *
822:             * @param statusField the status field
823:             * @since 3.0
824:             */
825:            void setStatusField(IStatusField statusField) {
826:                fStatusField = statusField;
827:                fIsStatusFieldExtension = fStatusField instanceof  IStatusFieldExtension;
828:            }
829:
830:            /*
831:             * @see org.eclipse.core.commands.IExecutionListener#notHandled(java.lang.String, org.eclipse.core.commands.NotHandledException)
832:             * @since 3.2
833:             */
834:            public void notHandled(String commandId,
835:                    NotHandledException exception) {
836:            }
837:
838:            /*
839:             * @see org.eclipse.core.commands.IExecutionListener#postExecuteFailure(java.lang.String, org.eclipse.core.commands.ExecutionException)
840:             * @since 3.2
841:             */
842:            public void postExecuteFailure(String commandId,
843:                    ExecutionException exception) {
844:            }
845:
846:            /*
847:             * @see org.eclipse.core.commands.IExecutionListener#postExecuteSuccess(java.lang.String, java.lang.Object)
848:             * @since 3.2
849:             */
850:            public void postExecuteSuccess(String commandId, Object returnValue) {
851:            }
852:
853:            /*
854:             * @see org.eclipse.core.commands.IExecutionListener#preExecute(java.lang.String, org.eclipse.core.commands.ExecutionEvent)
855:             * @since 3.2
856:             */
857:            public void preExecute(String commandId, ExecutionEvent event) {
858:                if (IWorkbenchActionDefinitionIds.FIND_INCREMENTAL
859:                        .equals(commandId)
860:                        || IWorkbenchActionDefinitionIds.FIND_INCREMENTAL_REVERSE
861:                                .equals(commandId))
862:                    return;
863:                leave();
864:            }
865:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.