1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.link;
13 import java.lang.reflect.InvocationTargetException;
15 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
16 import net.sourceforge.phpdt.ui.PreferenceConstants;
17 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.ui.WebUI;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.jface.dialogs.MessageDialog;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.jface.preference.PreferenceConverter;
25 //import org.eclipse.jface.text.Assert;
26 import org.eclipse.core.runtime.Assert;
27 import org.eclipse.jface.text.BadLocationException;
28 import org.eclipse.jface.text.BadPositionCategoryException;
29 import org.eclipse.jface.text.DefaultPositionUpdater;
30 import org.eclipse.jface.text.IDocument;
31 import org.eclipse.jface.text.IPositionUpdater;
32 import org.eclipse.jface.text.IRegion;
33 import org.eclipse.jface.text.IRewriteTarget;
34 import org.eclipse.jface.text.ITextInputListener;
35 import org.eclipse.jface.text.ITextListener;
36 import org.eclipse.jface.text.ITextViewer;
37 import org.eclipse.jface.text.ITextViewerExtension;
38 import org.eclipse.jface.text.ITextViewerExtension2;
39 import org.eclipse.jface.text.ITextViewerExtension5;
40 import org.eclipse.jface.text.Position;
41 import org.eclipse.jface.text.Region;
42 import org.eclipse.jface.text.TextEvent;
43 import org.eclipse.jface.util.IPropertyChangeListener;
44 import org.eclipse.jface.util.PropertyChangeEvent;
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.custom.StyledText;
47 import org.eclipse.swt.custom.VerifyKeyListener;
48 import org.eclipse.swt.events.ModifyEvent;
49 import org.eclipse.swt.events.ModifyListener;
50 import org.eclipse.swt.events.PaintEvent;
51 import org.eclipse.swt.events.PaintListener;
52 import org.eclipse.swt.events.ShellEvent;
53 import org.eclipse.swt.events.ShellListener;
54 import org.eclipse.swt.events.VerifyEvent;
55 import org.eclipse.swt.events.VerifyListener;
56 import org.eclipse.swt.graphics.Color;
57 import org.eclipse.swt.graphics.GC;
58 import org.eclipse.swt.graphics.Point;
59 import org.eclipse.swt.graphics.RGB;
60 import org.eclipse.swt.widgets.Display;
61 import org.eclipse.swt.widgets.Shell;
64 * A user interface for <code>LinkedPositionManager</code>, using
65 * <code>ITextViewer</code>.
67 public class LinkedPositionUI implements ILinkedPositionListener,
68 ITextInputListener, ITextListener, ModifyListener, VerifyListener,
69 VerifyKeyListener, PaintListener, IPropertyChangeListener,
73 * A listener for notification when the user cancelled the edit operation.
75 public interface ExitListener {
76 void exit(boolean accept);
79 public static class ExitFlags {
84 public ExitFlags(int flags, boolean doit) {
90 public interface ExitPolicy {
91 ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event,
92 int offset, int length);
96 private static final int UNINSTALL = 1; // uninstall linked position manager
98 public static final int COMMIT = 2; // commit changes
100 private static final int DOCUMENT_CHANGED = 4; // document has changed
102 public static final int UPDATE_CARET = 8; // update caret
104 private static final IPreferenceStore fgStore = WebUI
105 .getDefault().getPreferenceStore();
107 private static final String CARET_POSITION_PREFIX = "LinkedPositionUI.caret.position"; //$NON-NLS-1$
109 private static int fgCounter = 0;
111 private final ITextViewer fViewer;
113 private final LinkedPositionManager fManager;
115 private final IPositionUpdater fUpdater;
117 private final String fPositionCategoryName;
119 private Color fFrameColor;
121 private int fFinalCaretOffset = -1; // no final caret offset
123 private Position fFinalCaretPosition;
125 private Position fFramePosition;
127 private int fInitialOffset = -1;
129 private int fCaretOffset;
131 private ExitPolicy fExitPolicy;
133 private ExitListener fExitListener;
135 private boolean fNeedRedraw;
137 private String fContentType;
139 private Position fPreviousPosition;
141 // private ContentAssistant2 fAssistant;
144 * Flag that records the state of this ui object. As there are many
145 * different entities that may call leave or exit, these cannot always be
146 * sure whether the linked position infrastructure is still active. This is
147 * especially true for multithreaded situations.
149 private boolean fIsActive = false;
152 * Creates a user interface for <code>LinkedPositionManager</code>.
157 * the <code>LinkedPositionManager</code> managing a
158 * <code>IDocument</code> of the <code>ITextViewer</code>.
160 public LinkedPositionUI(ITextViewer viewer, LinkedPositionManager manager) {
161 Assert.isNotNull(viewer);
162 Assert.isNotNull(manager);
167 fPositionCategoryName = CARET_POSITION_PREFIX + (fgCounter++);
168 fUpdater = new DefaultPositionUpdater(fPositionCategoryName);
170 fManager.setLinkedPositionListener(this);
172 initializeHighlightColor(viewer);
176 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
178 public void propertyChange(PropertyChangeEvent event) {
179 if (event.getProperty().equals(
180 PreferenceConstants.EDITOR_LINKED_POSITION_COLOR)) {
181 initializeHighlightColor(fViewer);
186 private void initializeHighlightColor(ITextViewer viewer) {
188 if (fFrameColor != null)
189 fFrameColor.dispose();
191 StyledText text = viewer.getTextWidget();
193 Display display = text.getDisplay();
194 fFrameColor = createColor(fgStore,
195 PreferenceConstants.EDITOR_LINKED_POSITION_COLOR, display);
200 * Creates a color from the information stored in the given preference
201 * store. Returns <code>null</code> if there is no such information
204 private Color createColor(IPreferenceStore store, String key,
209 if (store.contains(key)) {
211 if (store.isDefault(key))
212 rgb = PreferenceConverter.getDefaultColor(store, key);
214 rgb = PreferenceConverter.getColor(store, key);
217 return new Color(display, rgb);
224 * Sets the initial offset.
228 // public void setInitialOffset(int offset) {
229 // fInitialOffset = offset;
233 * Sets the final position of the caret when the linked mode is exited
234 * successfully by leaving the last linked position using TAB. The set
235 * position will be a TAB stop as well as the positions configured in the
236 * <code>LinkedPositionManager</code>.
238 public void setFinalCaretOffset(int offset) {
239 fFinalCaretOffset = offset;
243 * Sets a <code>CancelListener</code> which is notified if the linked mode
244 * is exited unsuccessfully by hitting ESC.
246 public void setCancelListener(ExitListener listener) {
247 fExitListener = listener;
251 * Sets an <code>ExitPolicy</code> which decides when and how the linked
254 public void setExitPolicy(ExitPolicy policy) {
255 fExitPolicy = policy;
259 * @see LinkedPositionManager.LinkedPositionListener#setCurrentPositions(Position,
262 public void setCurrentPosition(Position position, int caretOffset) {
264 ;// JavaPlugin.log(new Status(IStatus.WARNING,
265 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
266 // not active: "+fPositionCategoryName, new
267 // IllegalStateException())); //$NON-NLS-1$
269 if (!fFramePosition.equals(position)) {
271 fFramePosition = position;
274 fCaretOffset = caretOffset;
278 * Enters the linked mode. The linked mode can be left by calling
281 * @see #exit(boolean)
283 public void enter() {
285 ;// JavaPlugin.log(new Status(IStatus.WARNING,
286 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
287 // already active: "+fPositionCategoryName, new
288 // IllegalStateException())); //$NON-NLS-1$
291 // JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(),
292 // IStatus.OK, "LinkedPositionUI activated: "+fPositionCategoryName,
293 // new Exception())); //$NON-NLS-1$
297 IDocument document = fViewer.getDocument();
298 document.addPositionCategory(fPositionCategoryName);
299 document.addPositionUpdater(fUpdater);
302 if (fFinalCaretOffset != -1) {
303 fFinalCaretPosition = new Position(fFinalCaretOffset);
305 .addPosition(fPositionCategoryName, fFinalCaretPosition);
307 } catch (BadLocationException e) {
308 handleException(fViewer.getTextWidget().getShell(), e);
310 } catch (BadPositionCategoryException e) {
312 Assert.isTrue(false);
315 fViewer.addTextInputListener(this);
316 fViewer.addTextListener(this);
318 ITextViewerExtension extension = (ITextViewerExtension) fViewer;
319 extension.prependVerifyKeyListener(this);
321 StyledText text = fViewer.getTextWidget();
322 text.addVerifyListener(this);
323 text.addModifyListener(this);
324 text.addPaintListener(this);
325 text.showSelection();
327 Shell shell = text.getShell();
328 shell.addShellListener(this);
330 fFramePosition = (fInitialOffset == -1) ? fManager.getFirstPosition()
331 : fManager.getPosition(fInitialOffset);
332 if (fFramePosition == null) {
333 leave(UNINSTALL | COMMIT | UPDATE_CARET);
337 fgStore.addPropertyChangeListener(this);
340 // fContentType= TextUtilities.getContentType(document,
341 // IJavaPartitions.JAVA_PARTITIONING, fFramePosition.offset);
342 // if (fViewer instanceof ITextViewerExtension2) {
343 // ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(fManager,
346 // Assert.isTrue(false);
349 // } catch (BadLocationException e) {
350 // handleException(fViewer.getTextWidget().getShell(), e);
353 fContentType = document.getContentType(fFramePosition.offset);
354 if (fViewer instanceof ITextViewerExtension2) {
355 ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(
356 fManager, fContentType);
358 Assert.isTrue(false);
361 } catch (BadLocationException e) {
362 handleException(fViewer.getTextWidget().getShell(), e);
365 // triggerContentAssist();
369 * @see net.sourceforge.phpdt.internal.ui.text.link.ILinkedPositionListener#exit(boolean)
371 public void exit(int flags) {
376 * Returns the cursor selection, after having entered the linked mode.
377 * <code>enter()</code> must be called prior to a call to this method.
379 public IRegion getSelectedRegion() {
381 ;// JavaPlugin.log(new Status(IStatus.WARNING,
382 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
383 // not active: "+fPositionCategoryName, new
384 // IllegalStateException())); //$NON-NLS-1$
386 if (fFramePosition == null)
387 return new Region(fFinalCaretOffset, 0);
389 return new Region(fFramePosition.getOffset(), fFramePosition
393 private void leave(int flags) {
395 ;// JavaPlugin.log(new Status(IStatus.WARNING,
396 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
397 // not active: "+fPositionCategoryName, new
398 // IllegalStateException())); //$NON-NLS-1$
401 // JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(),
402 // IStatus.OK, "LinkedPositionUI deactivated:
403 // "+fPositionCategoryName, new Exception())); //$NON-NLS-1$
408 if ((flags & UNINSTALL) != 0)
409 fManager.uninstall((flags & COMMIT) != 0);
411 fgStore.removePropertyChangeListener(this);
413 if (fFrameColor != null) {
414 fFrameColor.dispose();
418 StyledText text = fViewer.getTextWidget();
419 // bail out if the styled text is null, meaning the viewer has been
420 // disposed (-> document is null as well)
421 // see pr https://bugs.eclipse.org/bugs/show_bug.cgi?id=46821
425 text.removePaintListener(this);
426 text.removeModifyListener(this);
427 text.removeVerifyListener(this);
429 Shell shell = text.getShell();
430 shell.removeShellListener(this);
432 // if (fAssistant != null) {
433 // Display display= text.getDisplay();
434 // if (display != null && !display.isDisposed()) {
435 // display.asyncExec(new Runnable() {
436 // public void run() {
437 // if (fAssistant != null) {
438 // fAssistant.uninstall();
446 ITextViewerExtension extension = (ITextViewerExtension) fViewer;
447 extension.removeVerifyKeyListener(this);
449 IRewriteTarget target = extension.getRewriteTarget();
450 target.endCompoundChange();
452 if (fViewer instanceof ITextViewerExtension2 && fContentType != null)
453 ((ITextViewerExtension2) fViewer).removeAutoEditStrategy(fManager,
457 fViewer.removeTextListener(this);
458 fViewer.removeTextInputListener(this);
461 IDocument document = fViewer.getDocument();
463 if (((flags & COMMIT) != 0) && ((flags & DOCUMENT_CHANGED) == 0)
464 && ((flags & UPDATE_CARET) != 0)) {
465 Position[] positions = document
466 .getPositions(fPositionCategoryName);
467 if ((positions != null) && (positions.length != 0)) {
469 if (fViewer instanceof ITextViewerExtension5) {
470 ITextViewerExtension5 extension3 = (ITextViewerExtension5) fViewer;
471 int widgetOffset = extension3
472 .modelOffset2WidgetOffset(positions[0]
474 if (widgetOffset >= 0)
475 text.setSelection(widgetOffset, widgetOffset);
478 IRegion region = fViewer.getVisibleRegion();
479 int offset = positions[0].getOffset()
480 - region.getOffset();
481 if ((offset >= 0) && (offset <= region.getLength()))
482 text.setSelection(offset, offset);
487 document.removePositionUpdater(fUpdater);
488 document.removePositionCategory(fPositionCategoryName);
490 if (fExitListener != null)
491 fExitListener.exit(((flags & COMMIT) != 0)
492 || ((flags & DOCUMENT_CHANGED) != 0));
494 } catch (BadPositionCategoryException e) {
496 Assert.isTrue(false);
499 if ((flags & DOCUMENT_CHANGED) == 0)
503 private void next() {
505 ;// JavaPlugin.log(new Status(IStatus.WARNING,
506 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
507 // not active: "+fPositionCategoryName, new
508 // IllegalStateException())); //$NON-NLS-1$
512 if (fFramePosition == fFinalCaretPosition)
513 fFramePosition = fManager.getFirstPosition();
515 fFramePosition = fManager.getNextPosition(fFramePosition
517 if (fFramePosition == null) {
518 if (fFinalCaretPosition != null)
519 fFramePosition = fFinalCaretPosition;
521 fFramePosition = fManager.getFirstPosition();
523 if (fFramePosition == null) {
524 leave(UNINSTALL | COMMIT | UPDATE_CARET);
527 // triggerContentAssist();
532 private void previous() {
534 ;// JavaPlugin.log(new Status(IStatus.WARNING,
535 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
536 // not active: "+fPositionCategoryName, new
537 // IllegalStateException())); //$NON-NLS-1$
541 fFramePosition = fManager.getPreviousPosition(fFramePosition
543 if (fFramePosition == null) {
544 if (fFinalCaretPosition != null)
545 fFramePosition = fFinalCaretPosition;
547 fFramePosition = fManager.getLastPosition();
549 if (fFramePosition == null) {
550 leave(UNINSTALL | COMMIT | UPDATE_CARET);
553 // triggerContentAssist();
558 /** Trigger content assist on choice positions */
559 // private void triggerContentAssist() {
560 // if (fFramePosition instanceof ProposalPosition) {
562 // ProposalPosition pp= (ProposalPosition) fFramePosition;
563 // initializeContentAssistant();
564 // if (fAssistant == null)
566 // fAssistant.setCompletions(pp.getChoices());
567 // fAssistant.showPossibleCompletions();
569 // if (fAssistant != null)
570 // fAssistant.setCompletions(new ICompletionProposal[0]);
573 /** Lazy initialize content assistant for this linked ui */
574 // private void initializeContentAssistant() {
575 // if (fAssistant != null)
577 // fAssistant= new ContentAssistant2();
578 // fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING);
579 // fAssistant.install(fViewer);
582 * @see VerifyKeyListener#verifyKey(VerifyEvent)
584 public void verifyKey(VerifyEvent event) {
586 if (!event.doit || !fIsActive)
589 Point selection = fViewer.getSelectedRange();
590 int offset = selection.x;
591 int length = selection.y;
593 ExitFlags exitFlags = fExitPolicy == null ? null : fExitPolicy.doExit(
594 fManager, event, offset, length);
595 if (exitFlags != null) {
596 leave(UNINSTALL | exitFlags.flags);
597 event.doit = exitFlags.doit;
601 switch (event.character) {
602 // [SHIFT-]TAB = hop between edit boxes
604 // if tab was treated as a document change, would it exceed variable
606 if (!LinkedPositionManager.includes(fFramePosition, offset, length)) {
607 leave(UNINSTALL | COMMIT);
612 if (event.stateMask == SWT.SHIFT)
621 case 0x0A: // Ctrl+Enter
623 // if (fAssistant != null && fAssistant.wasProposalChosen()) {
625 // event.doit= false;
629 // if enter was treated as a document change, would it exceed
631 if (!LinkedPositionManager.includes(fFramePosition, offset, length)
632 || (fFramePosition == fFinalCaretPosition)) {
633 leave(UNINSTALL | COMMIT);
638 leave(UNINSTALL | COMMIT | UPDATE_CARET);
644 leave(UNINSTALL | COMMIT);
649 leave(UNINSTALL | COMMIT);
654 if (event.character != 0) {
655 if (!controlUndoBehavior(offset, length)
656 || fFramePosition == fFinalCaretPosition) {
657 leave(UNINSTALL | COMMIT);
664 private boolean controlUndoBehavior(int offset, int length) {
666 Position position = fManager.getEmbracingPosition(offset, length);
667 if (position != null) {
669 ITextViewerExtension extension = (ITextViewerExtension) fViewer;
670 IRewriteTarget target = extension.getRewriteTarget();
672 if (fPreviousPosition != null
673 && !fPreviousPosition.equals(position))
674 target.endCompoundChange();
675 target.beginCompoundChange();
678 fPreviousPosition = position;
679 return fPreviousPosition != null;
683 * @see VerifyListener#verifyText(VerifyEvent)
685 public void verifyText(VerifyEvent event) {
692 if (fViewer instanceof ITextViewerExtension5) {
693 ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
694 IRegion modelRange = extension.widgetRange2ModelRange(new Region(
695 event.start, event.end - event.start));
696 if (modelRange == null)
699 offset = modelRange.getOffset();
700 length = modelRange.getLength();
703 IRegion visibleRegion = fViewer.getVisibleRegion();
704 offset = event.start + visibleRegion.getOffset();
705 length = event.end - event.start;
708 // allow changes only within linked positions when coming through UI
709 if (!fManager.anyPositionIncludes(offset, length))
710 leave(UNINSTALL | COMMIT);
714 * @see PaintListener#paintControl(PaintEvent)
716 public void paintControl(PaintEvent event) {
717 if (fFramePosition == null)
720 IRegion widgetRange = asWidgetRange(fFramePosition);
721 if (widgetRange == null) {
722 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
726 int offset = widgetRange.getOffset();
727 int length = widgetRange.getLength();
729 StyledText text = fViewer.getTextWidget();
732 Point minLocation = getMinimumLocation(text, offset, length);
733 Point maxLocation = getMaximumLocation(text, offset, length);
735 int x1 = minLocation.x;
736 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
737 int y = minLocation.y + text.getLineHeight() - 1;
740 gc.setForeground(fFrameColor);
741 gc.drawLine(x1, y, x2, y);
744 protected IRegion asWidgetRange(Position position) {
745 if (fViewer instanceof ITextViewerExtension5) {
747 ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
748 return extension.modelRange2WidgetRange(new Region(position
749 .getOffset(), position.getLength()));
753 IRegion region = fViewer.getVisibleRegion();
754 if (includes(region, position))
755 return new Region(position.getOffset() - region.getOffset(),
756 position.getLength());
762 private static Point getMinimumLocation(StyledText text, int offset,
764 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
766 for (int i = 0; i <= length; i++) {
767 Point location = text.getLocationAtOffset(offset + i);
769 if (location.x < minLocation.x)
770 minLocation.x = location.x;
771 if (location.y < minLocation.y)
772 minLocation.y = location.y;
778 private static Point getMaximumLocation(StyledText text, int offset,
780 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
782 for (int i = 0; i <= length; i++) {
783 Point location = text.getLocationAtOffset(offset + i);
785 if (location.x > maxLocation.x)
786 maxLocation.x = location.x;
787 if (location.y > maxLocation.y)
788 maxLocation.y = location.y;
794 private void redrawRegion() {
795 IRegion widgetRange = asWidgetRange(fFramePosition);
796 if (widgetRange == null) {
797 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
801 StyledText text = fViewer.getTextWidget();
802 if (text != null && !text.isDisposed())
803 text.redrawRange(widgetRange.getOffset(), widgetRange.getLength(),
807 private void selectRegion() {
809 IRegion widgetRange = asWidgetRange(fFramePosition);
810 if (widgetRange == null) {
811 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
815 StyledText text = fViewer.getTextWidget();
816 if (text != null && !text.isDisposed()) {
817 int start = widgetRange.getOffset();
818 int end = widgetRange.getLength() + start;
819 text.setSelection(start, end);
823 private void updateCaret() {
825 IRegion widgetRange = asWidgetRange(fFramePosition);
826 if (widgetRange == null) {
827 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
831 int offset = widgetRange.getOffset() + fCaretOffset;
832 StyledText text = fViewer.getTextWidget();
833 if (text != null && !text.isDisposed())
834 text.setCaretOffset(offset);
838 * @see ModifyListener#modifyText(ModifyEvent)
840 public void modifyText(ModifyEvent e) {
841 // reposition caret after StyledText
846 private static void handleException(Shell shell, Exception e) {
847 String title = LinkedPositionMessages
848 .getString("LinkedPositionUI.error.title"); //$NON-NLS-1$
849 if (e instanceof CoreException)
850 ExceptionHandler.handle((CoreException) e, shell, title, null);
851 else if (e instanceof InvocationTargetException)
852 ExceptionHandler.handle((InvocationTargetException) e, shell,
855 MessageDialog.openError(shell, title, e.getMessage());
861 * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument,
864 public void inputDocumentAboutToBeChanged(IDocument oldInput,
865 IDocument newInput) {
866 // 5326: leave linked mode on document change
867 int flags = UNINSTALL | COMMIT
868 | (oldInput.equals(newInput) ? 0 : DOCUMENT_CHANGED);
873 * @see ITextInputListener#inputDocumentChanged(IDocument, IDocument)
875 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
878 private static boolean includes(IRegion region, Position position) {
879 return position.getOffset() >= region.getOffset()
880 && position.getOffset() + position.getLength() <= region
882 + region.getLength();
886 * @see org.eclipse.jface.text.ITextListener#textChanged(TextEvent)
888 public void textChanged(TextEvent event) {
897 * @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
899 public void shellActivated(ShellEvent event) {
903 * @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
905 public void shellClosed(ShellEvent event) {
906 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
910 * @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
912 public void shellDeactivated(ShellEvent event) {
913 // don't deactivate on focus lost, since the proposal popups may take
915 // plus: it doesn't hurt if you can check with another window without
916 // losing linked mode
917 // since there is no intrusive popup sticking out.
919 // need to check first what happens on reentering based on an open
921 // Seems to be no problem
923 // TODO check whether we can leave it or uncomment it after debugging
924 // PS: why DOCUMENT_CHANGED? We want to trigger a redraw! (Shell
925 // deactivated does not mean
926 // it is not visible any longer.
927 // leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
930 // Check with content assistant and only leave if its not the proposal
931 // shell that took the
937 // if (fAssistant == null || fViewer == null || (text=
938 // fViewer.getTextWidget()) == null
939 // || (display= text.getDisplay()) == null || display.isDisposed()) {
940 if (fViewer == null || (text = fViewer.getTextWidget()) == null
941 || (display = text.getDisplay()) == null
942 || display.isDisposed()) {
943 leave(UNINSTALL | COMMIT);
945 // Post in UI thread since the assistant popup will only get the
946 // focus after we lose it.
947 display.asyncExec(new Runnable() {
949 // TODO add isDisposed / isUninstalled / hasLeft check? for
950 // now: check for content type,
951 // since it gets nullified in leave()
952 if (fIsActive) {// && (fAssistant == null ||
953 // !fAssistant.hasFocus())) {
954 leave(UNINSTALL | COMMIT);
962 * @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
964 public void shellDeiconified(ShellEvent event) {
968 * @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
970 public void shellIconified(ShellEvent event) {
971 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);