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;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.jface.dialogs.MessageDialog;
21 import org.eclipse.jface.preference.IPreferenceStore;
22 import org.eclipse.jface.preference.PreferenceConverter;
23 import org.eclipse.jface.text.Assert;
24 import org.eclipse.jface.text.BadLocationException;
25 import org.eclipse.jface.text.BadPositionCategoryException;
26 import org.eclipse.jface.text.DefaultPositionUpdater;
27 import org.eclipse.jface.text.IDocument;
28 import org.eclipse.jface.text.IPositionUpdater;
29 import org.eclipse.jface.text.IRegion;
30 import org.eclipse.jface.text.IRewriteTarget;
31 import org.eclipse.jface.text.ITextInputListener;
32 import org.eclipse.jface.text.ITextListener;
33 import org.eclipse.jface.text.ITextViewer;
34 import org.eclipse.jface.text.ITextViewerExtension;
35 import org.eclipse.jface.text.ITextViewerExtension2;
36 import org.eclipse.jface.text.ITextViewerExtension5;
37 import org.eclipse.jface.text.Position;
38 import org.eclipse.jface.text.Region;
39 import org.eclipse.jface.text.TextEvent;
40 import org.eclipse.jface.util.IPropertyChangeListener;
41 import org.eclipse.jface.util.PropertyChangeEvent;
42 import org.eclipse.swt.SWT;
43 import org.eclipse.swt.custom.StyledText;
44 import org.eclipse.swt.custom.VerifyKeyListener;
45 import org.eclipse.swt.events.ModifyEvent;
46 import org.eclipse.swt.events.ModifyListener;
47 import org.eclipse.swt.events.PaintEvent;
48 import org.eclipse.swt.events.PaintListener;
49 import org.eclipse.swt.events.ShellEvent;
50 import org.eclipse.swt.events.ShellListener;
51 import org.eclipse.swt.events.VerifyEvent;
52 import org.eclipse.swt.events.VerifyListener;
53 import org.eclipse.swt.graphics.Color;
54 import org.eclipse.swt.graphics.GC;
55 import org.eclipse.swt.graphics.Point;
56 import org.eclipse.swt.graphics.RGB;
57 import org.eclipse.swt.widgets.Display;
58 import org.eclipse.swt.widgets.Shell;
61 * A user interface for <code>LinkedPositionManager</code>, using
62 * <code>ITextViewer</code>.
64 public class LinkedPositionUI implements ILinkedPositionListener,
65 ITextInputListener, ITextListener, ModifyListener, VerifyListener,
66 VerifyKeyListener, PaintListener, IPropertyChangeListener,
70 * A listener for notification when the user cancelled the edit operation.
72 public interface ExitListener {
73 void exit(boolean accept);
76 public static class ExitFlags {
81 public ExitFlags(int flags, boolean doit) {
87 public interface ExitPolicy {
88 ExitFlags doExit(LinkedPositionManager manager, VerifyEvent event,
89 int offset, int length);
93 private static final int UNINSTALL = 1; // uninstall linked position manager
95 public static final int COMMIT = 2; // commit changes
97 private static final int DOCUMENT_CHANGED = 4; // document has changed
99 public static final int UPDATE_CARET = 8; // update caret
101 private static final IPreferenceStore fgStore = PHPeclipsePlugin
102 .getDefault().getPreferenceStore();
104 private static final String CARET_POSITION_PREFIX = "LinkedPositionUI.caret.position"; //$NON-NLS-1$
106 private static int fgCounter = 0;
108 private final ITextViewer fViewer;
110 private final LinkedPositionManager fManager;
112 private final IPositionUpdater fUpdater;
114 private final String fPositionCategoryName;
116 private Color fFrameColor;
118 private int fFinalCaretOffset = -1; // no final caret offset
120 private Position fFinalCaretPosition;
122 private Position fFramePosition;
124 private int fInitialOffset = -1;
126 private int fCaretOffset;
128 private ExitPolicy fExitPolicy;
130 private ExitListener fExitListener;
132 private boolean fNeedRedraw;
134 private String fContentType;
136 private Position fPreviousPosition;
138 // private ContentAssistant2 fAssistant;
141 * Flag that records the state of this ui object. As there are many
142 * different entities that may call leave or exit, these cannot always be
143 * sure whether the linked position infrastructure is still active. This is
144 * especially true for multithreaded situations.
146 private boolean fIsActive = false;
149 * Creates a user interface for <code>LinkedPositionManager</code>.
154 * the <code>LinkedPositionManager</code> managing a
155 * <code>IDocument</code> of the <code>ITextViewer</code>.
157 public LinkedPositionUI(ITextViewer viewer, LinkedPositionManager manager) {
158 Assert.isNotNull(viewer);
159 Assert.isNotNull(manager);
164 fPositionCategoryName = CARET_POSITION_PREFIX + (fgCounter++);
165 fUpdater = new DefaultPositionUpdater(fPositionCategoryName);
167 fManager.setLinkedPositionListener(this);
169 initializeHighlightColor(viewer);
173 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
175 public void propertyChange(PropertyChangeEvent event) {
176 if (event.getProperty().equals(
177 PreferenceConstants.EDITOR_LINKED_POSITION_COLOR)) {
178 initializeHighlightColor(fViewer);
183 private void initializeHighlightColor(ITextViewer viewer) {
185 if (fFrameColor != null)
186 fFrameColor.dispose();
188 StyledText text = viewer.getTextWidget();
190 Display display = text.getDisplay();
191 fFrameColor = createColor(fgStore,
192 PreferenceConstants.EDITOR_LINKED_POSITION_COLOR, display);
197 * Creates a color from the information stored in the given preference
198 * store. Returns <code>null</code> if there is no such information
201 private Color createColor(IPreferenceStore store, String key,
206 if (store.contains(key)) {
208 if (store.isDefault(key))
209 rgb = PreferenceConverter.getDefaultColor(store, key);
211 rgb = PreferenceConverter.getColor(store, key);
214 return new Color(display, rgb);
221 * Sets the initial offset.
225 public void setInitialOffset(int offset) {
226 fInitialOffset = offset;
230 * Sets the final position of the caret when the linked mode is exited
231 * successfully by leaving the last linked position using TAB. The set
232 * position will be a TAB stop as well as the positions configured in the
233 * <code>LinkedPositionManager</code>.
235 public void setFinalCaretOffset(int offset) {
236 fFinalCaretOffset = offset;
240 * Sets a <code>CancelListener</code> which is notified if the linked mode
241 * is exited unsuccessfully by hitting ESC.
243 public void setCancelListener(ExitListener listener) {
244 fExitListener = listener;
248 * Sets an <code>ExitPolicy</code> which decides when and how the linked
251 public void setExitPolicy(ExitPolicy policy) {
252 fExitPolicy = policy;
256 * @see LinkedPositionManager.LinkedPositionListener#setCurrentPositions(Position,
259 public void setCurrentPosition(Position position, int caretOffset) {
261 ;// JavaPlugin.log(new Status(IStatus.WARNING,
262 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
263 // not active: "+fPositionCategoryName, new
264 // IllegalStateException())); //$NON-NLS-1$
266 if (!fFramePosition.equals(position)) {
268 fFramePosition = position;
271 fCaretOffset = caretOffset;
275 * Enters the linked mode. The linked mode can be left by calling
278 * @see #exit(boolean)
280 public void enter() {
282 ;// JavaPlugin.log(new Status(IStatus.WARNING,
283 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
284 // already active: "+fPositionCategoryName, new
285 // IllegalStateException())); //$NON-NLS-1$
288 // JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(),
289 // IStatus.OK, "LinkedPositionUI activated: "+fPositionCategoryName,
290 // new Exception())); //$NON-NLS-1$
294 IDocument document = fViewer.getDocument();
295 document.addPositionCategory(fPositionCategoryName);
296 document.addPositionUpdater(fUpdater);
299 if (fFinalCaretOffset != -1) {
300 fFinalCaretPosition = new Position(fFinalCaretOffset);
302 .addPosition(fPositionCategoryName, fFinalCaretPosition);
304 } catch (BadLocationException e) {
305 handleException(fViewer.getTextWidget().getShell(), e);
307 } catch (BadPositionCategoryException e) {
308 PHPeclipsePlugin.log(e);
309 Assert.isTrue(false);
312 fViewer.addTextInputListener(this);
313 fViewer.addTextListener(this);
315 ITextViewerExtension extension = (ITextViewerExtension) fViewer;
316 extension.prependVerifyKeyListener(this);
318 StyledText text = fViewer.getTextWidget();
319 text.addVerifyListener(this);
320 text.addModifyListener(this);
321 text.addPaintListener(this);
322 text.showSelection();
324 Shell shell = text.getShell();
325 shell.addShellListener(this);
327 fFramePosition = (fInitialOffset == -1) ? fManager.getFirstPosition()
328 : fManager.getPosition(fInitialOffset);
329 if (fFramePosition == null) {
330 leave(UNINSTALL | COMMIT | UPDATE_CARET);
334 fgStore.addPropertyChangeListener(this);
337 // fContentType= TextUtilities.getContentType(document,
338 // IJavaPartitions.JAVA_PARTITIONING, fFramePosition.offset);
339 // if (fViewer instanceof ITextViewerExtension2) {
340 // ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(fManager,
343 // Assert.isTrue(false);
346 // } catch (BadLocationException e) {
347 // handleException(fViewer.getTextWidget().getShell(), e);
350 fContentType = document.getContentType(fFramePosition.offset);
351 if (fViewer instanceof ITextViewerExtension2) {
352 ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(
353 fManager, fContentType);
355 Assert.isTrue(false);
358 } catch (BadLocationException e) {
359 handleException(fViewer.getTextWidget().getShell(), e);
362 // triggerContentAssist();
366 * @see net.sourceforge.phpdt.internal.ui.text.link.ILinkedPositionListener#exit(boolean)
368 public void exit(int flags) {
373 * Returns the cursor selection, after having entered the linked mode.
374 * <code>enter()</code> must be called prior to a call to this method.
376 public IRegion getSelectedRegion() {
378 ;// JavaPlugin.log(new Status(IStatus.WARNING,
379 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
380 // not active: "+fPositionCategoryName, new
381 // IllegalStateException())); //$NON-NLS-1$
383 if (fFramePosition == null)
384 return new Region(fFinalCaretOffset, 0);
386 return new Region(fFramePosition.getOffset(), fFramePosition
390 private void leave(int flags) {
392 ;// JavaPlugin.log(new Status(IStatus.WARNING,
393 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
394 // not active: "+fPositionCategoryName, new
395 // IllegalStateException())); //$NON-NLS-1$
398 // JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(),
399 // IStatus.OK, "LinkedPositionUI deactivated:
400 // "+fPositionCategoryName, new Exception())); //$NON-NLS-1$
405 if ((flags & UNINSTALL) != 0)
406 fManager.uninstall((flags & COMMIT) != 0);
408 fgStore.removePropertyChangeListener(this);
410 if (fFrameColor != null) {
411 fFrameColor.dispose();
415 StyledText text = fViewer.getTextWidget();
416 // bail out if the styled text is null, meaning the viewer has been
417 // disposed (-> document is null as well)
418 // see pr https://bugs.eclipse.org/bugs/show_bug.cgi?id=46821
422 text.removePaintListener(this);
423 text.removeModifyListener(this);
424 text.removeVerifyListener(this);
426 Shell shell = text.getShell();
427 shell.removeShellListener(this);
429 // if (fAssistant != null) {
430 // Display display= text.getDisplay();
431 // if (display != null && !display.isDisposed()) {
432 // display.asyncExec(new Runnable() {
433 // public void run() {
434 // if (fAssistant != null) {
435 // fAssistant.uninstall();
443 ITextViewerExtension extension = (ITextViewerExtension) fViewer;
444 extension.removeVerifyKeyListener(this);
446 IRewriteTarget target = extension.getRewriteTarget();
447 target.endCompoundChange();
449 if (fViewer instanceof ITextViewerExtension2 && fContentType != null)
450 ((ITextViewerExtension2) fViewer).removeAutoEditStrategy(fManager,
454 fViewer.removeTextListener(this);
455 fViewer.removeTextInputListener(this);
458 IDocument document = fViewer.getDocument();
460 if (((flags & COMMIT) != 0) && ((flags & DOCUMENT_CHANGED) == 0)
461 && ((flags & UPDATE_CARET) != 0)) {
462 Position[] positions = document
463 .getPositions(fPositionCategoryName);
464 if ((positions != null) && (positions.length != 0)) {
466 if (fViewer instanceof ITextViewerExtension5) {
467 ITextViewerExtension5 extension3 = (ITextViewerExtension5) fViewer;
468 int widgetOffset = extension3
469 .modelOffset2WidgetOffset(positions[0]
471 if (widgetOffset >= 0)
472 text.setSelection(widgetOffset, widgetOffset);
475 IRegion region = fViewer.getVisibleRegion();
476 int offset = positions[0].getOffset()
477 - region.getOffset();
478 if ((offset >= 0) && (offset <= region.getLength()))
479 text.setSelection(offset, offset);
484 document.removePositionUpdater(fUpdater);
485 document.removePositionCategory(fPositionCategoryName);
487 if (fExitListener != null)
488 fExitListener.exit(((flags & COMMIT) != 0)
489 || ((flags & DOCUMENT_CHANGED) != 0));
491 } catch (BadPositionCategoryException e) {
492 PHPeclipsePlugin.log(e);
493 Assert.isTrue(false);
496 if ((flags & DOCUMENT_CHANGED) == 0)
500 private void next() {
502 ;// JavaPlugin.log(new Status(IStatus.WARNING,
503 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
504 // not active: "+fPositionCategoryName, new
505 // IllegalStateException())); //$NON-NLS-1$
509 if (fFramePosition == fFinalCaretPosition)
510 fFramePosition = fManager.getFirstPosition();
512 fFramePosition = fManager.getNextPosition(fFramePosition
514 if (fFramePosition == null) {
515 if (fFinalCaretPosition != null)
516 fFramePosition = fFinalCaretPosition;
518 fFramePosition = fManager.getFirstPosition();
520 if (fFramePosition == null) {
521 leave(UNINSTALL | COMMIT | UPDATE_CARET);
524 // triggerContentAssist();
529 private void previous() {
531 ;// JavaPlugin.log(new Status(IStatus.WARNING,
532 // JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is
533 // not active: "+fPositionCategoryName, new
534 // IllegalStateException())); //$NON-NLS-1$
538 fFramePosition = fManager.getPreviousPosition(fFramePosition
540 if (fFramePosition == null) {
541 if (fFinalCaretPosition != null)
542 fFramePosition = fFinalCaretPosition;
544 fFramePosition = fManager.getLastPosition();
546 if (fFramePosition == null) {
547 leave(UNINSTALL | COMMIT | UPDATE_CARET);
550 // triggerContentAssist();
555 /** Trigger content assist on choice positions */
556 // private void triggerContentAssist() {
557 // if (fFramePosition instanceof ProposalPosition) {
559 // ProposalPosition pp= (ProposalPosition) fFramePosition;
560 // initializeContentAssistant();
561 // if (fAssistant == null)
563 // fAssistant.setCompletions(pp.getChoices());
564 // fAssistant.showPossibleCompletions();
566 // if (fAssistant != null)
567 // fAssistant.setCompletions(new ICompletionProposal[0]);
570 /** Lazy initialize content assistant for this linked ui */
571 // private void initializeContentAssistant() {
572 // if (fAssistant != null)
574 // fAssistant= new ContentAssistant2();
575 // fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING);
576 // fAssistant.install(fViewer);
579 * @see VerifyKeyListener#verifyKey(VerifyEvent)
581 public void verifyKey(VerifyEvent event) {
583 if (!event.doit || !fIsActive)
586 Point selection = fViewer.getSelectedRange();
587 int offset = selection.x;
588 int length = selection.y;
590 ExitFlags exitFlags = fExitPolicy == null ? null : fExitPolicy.doExit(
591 fManager, event, offset, length);
592 if (exitFlags != null) {
593 leave(UNINSTALL | exitFlags.flags);
594 event.doit = exitFlags.doit;
598 switch (event.character) {
599 // [SHIFT-]TAB = hop between edit boxes
601 // if tab was treated as a document change, would it exceed variable
603 if (!LinkedPositionManager.includes(fFramePosition, offset, length)) {
604 leave(UNINSTALL | COMMIT);
609 if (event.stateMask == SWT.SHIFT)
618 case 0x0A: // Ctrl+Enter
620 // if (fAssistant != null && fAssistant.wasProposalChosen()) {
622 // event.doit= false;
626 // if enter was treated as a document change, would it exceed
628 if (!LinkedPositionManager.includes(fFramePosition, offset, length)
629 || (fFramePosition == fFinalCaretPosition)) {
630 leave(UNINSTALL | COMMIT);
635 leave(UNINSTALL | COMMIT | UPDATE_CARET);
641 leave(UNINSTALL | COMMIT);
646 leave(UNINSTALL | COMMIT);
651 if (event.character != 0) {
652 if (!controlUndoBehavior(offset, length)
653 || fFramePosition == fFinalCaretPosition) {
654 leave(UNINSTALL | COMMIT);
661 private boolean controlUndoBehavior(int offset, int length) {
663 Position position = fManager.getEmbracingPosition(offset, length);
664 if (position != null) {
666 ITextViewerExtension extension = (ITextViewerExtension) fViewer;
667 IRewriteTarget target = extension.getRewriteTarget();
669 if (fPreviousPosition != null
670 && !fPreviousPosition.equals(position))
671 target.endCompoundChange();
672 target.beginCompoundChange();
675 fPreviousPosition = position;
676 return fPreviousPosition != null;
680 * @see VerifyListener#verifyText(VerifyEvent)
682 public void verifyText(VerifyEvent event) {
689 if (fViewer instanceof ITextViewerExtension5) {
690 ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
691 IRegion modelRange = extension.widgetRange2ModelRange(new Region(
692 event.start, event.end - event.start));
693 if (modelRange == null)
696 offset = modelRange.getOffset();
697 length = modelRange.getLength();
700 IRegion visibleRegion = fViewer.getVisibleRegion();
701 offset = event.start + visibleRegion.getOffset();
702 length = event.end - event.start;
705 // allow changes only within linked positions when coming through UI
706 if (!fManager.anyPositionIncludes(offset, length))
707 leave(UNINSTALL | COMMIT);
711 * @see PaintListener#paintControl(PaintEvent)
713 public void paintControl(PaintEvent event) {
714 if (fFramePosition == null)
717 IRegion widgetRange = asWidgetRange(fFramePosition);
718 if (widgetRange == null) {
719 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
723 int offset = widgetRange.getOffset();
724 int length = widgetRange.getLength();
726 StyledText text = fViewer.getTextWidget();
729 Point minLocation = getMinimumLocation(text, offset, length);
730 Point maxLocation = getMaximumLocation(text, offset, length);
732 int x1 = minLocation.x;
733 int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
734 int y = minLocation.y + text.getLineHeight() - 1;
737 gc.setForeground(fFrameColor);
738 gc.drawLine(x1, y, x2, y);
741 protected IRegion asWidgetRange(Position position) {
742 if (fViewer instanceof ITextViewerExtension5) {
744 ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
745 return extension.modelRange2WidgetRange(new Region(position
746 .getOffset(), position.getLength()));
750 IRegion region = fViewer.getVisibleRegion();
751 if (includes(region, position))
752 return new Region(position.getOffset() - region.getOffset(),
753 position.getLength());
759 private static Point getMinimumLocation(StyledText text, int offset,
761 Point minLocation = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
763 for (int i = 0; i <= length; i++) {
764 Point location = text.getLocationAtOffset(offset + i);
766 if (location.x < minLocation.x)
767 minLocation.x = location.x;
768 if (location.y < minLocation.y)
769 minLocation.y = location.y;
775 private static Point getMaximumLocation(StyledText text, int offset,
777 Point maxLocation = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE);
779 for (int i = 0; i <= length; i++) {
780 Point location = text.getLocationAtOffset(offset + i);
782 if (location.x > maxLocation.x)
783 maxLocation.x = location.x;
784 if (location.y > maxLocation.y)
785 maxLocation.y = location.y;
791 private void redrawRegion() {
792 IRegion widgetRange = asWidgetRange(fFramePosition);
793 if (widgetRange == null) {
794 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
798 StyledText text = fViewer.getTextWidget();
799 if (text != null && !text.isDisposed())
800 text.redrawRange(widgetRange.getOffset(), widgetRange.getLength(),
804 private void selectRegion() {
806 IRegion widgetRange = asWidgetRange(fFramePosition);
807 if (widgetRange == null) {
808 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
812 StyledText text = fViewer.getTextWidget();
813 if (text != null && !text.isDisposed()) {
814 int start = widgetRange.getOffset();
815 int end = widgetRange.getLength() + start;
816 text.setSelection(start, end);
820 private void updateCaret() {
822 IRegion widgetRange = asWidgetRange(fFramePosition);
823 if (widgetRange == null) {
824 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
828 int offset = widgetRange.getOffset() + fCaretOffset;
829 StyledText text = fViewer.getTextWidget();
830 if (text != null && !text.isDisposed())
831 text.setCaretOffset(offset);
835 * @see ModifyListener#modifyText(ModifyEvent)
837 public void modifyText(ModifyEvent e) {
838 // reposition caret after StyledText
843 private static void handleException(Shell shell, Exception e) {
844 String title = LinkedPositionMessages
845 .getString("LinkedPositionUI.error.title"); //$NON-NLS-1$
846 if (e instanceof CoreException)
847 ExceptionHandler.handle((CoreException) e, shell, title, null);
848 else if (e instanceof InvocationTargetException)
849 ExceptionHandler.handle((InvocationTargetException) e, shell,
852 MessageDialog.openError(shell, title, e.getMessage());
853 PHPeclipsePlugin.log(e);
858 * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument,
861 public void inputDocumentAboutToBeChanged(IDocument oldInput,
862 IDocument newInput) {
863 // 5326: leave linked mode on document change
864 int flags = UNINSTALL | COMMIT
865 | (oldInput.equals(newInput) ? 0 : DOCUMENT_CHANGED);
870 * @see ITextInputListener#inputDocumentChanged(IDocument, IDocument)
872 public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
875 private static boolean includes(IRegion region, Position position) {
876 return position.getOffset() >= region.getOffset()
877 && position.getOffset() + position.getLength() <= region
879 + region.getLength();
883 * @see org.eclipse.jface.text.ITextListener#textChanged(TextEvent)
885 public void textChanged(TextEvent event) {
894 * @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
896 public void shellActivated(ShellEvent event) {
900 * @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
902 public void shellClosed(ShellEvent event) {
903 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
907 * @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
909 public void shellDeactivated(ShellEvent event) {
910 // don't deactivate on focus lost, since the proposal popups may take
912 // plus: it doesn't hurt if you can check with another window without
913 // losing linked mode
914 // since there is no intrusive popup sticking out.
916 // need to check first what happens on reentering based on an open
918 // Seems to be no problem
920 // TODO check whether we can leave it or uncomment it after debugging
921 // PS: why DOCUMENT_CHANGED? We want to trigger a redraw! (Shell
922 // deactivated does not mean
923 // it is not visible any longer.
924 // leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);
927 // Check with content assistant and only leave if its not the proposal
928 // shell that took the
934 // if (fAssistant == null || fViewer == null || (text=
935 // fViewer.getTextWidget()) == null
936 // || (display= text.getDisplay()) == null || display.isDisposed()) {
937 if (fViewer == null || (text = fViewer.getTextWidget()) == null
938 || (display = text.getDisplay()) == null
939 || display.isDisposed()) {
940 leave(UNINSTALL | COMMIT);
942 // Post in UI thread since the assistant popup will only get the
943 // focus after we lose it.
944 display.asyncExec(new Runnable() {
946 // TODO add isDisposed / isUninstalled / hasLeft check? for
947 // now: check for content type,
948 // since it gets nullified in leave()
949 if (fIsActive) {// && (fAssistant == null ||
950 // !fAssistant.hasFocus())) {
951 leave(UNINSTALL | COMMIT);
959 * @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
961 public void shellDeiconified(ShellEvent event) {
965 * @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
967 public void shellIconified(ShellEvent event) {
968 leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED);