remove incorrect assertion
[fedora-idea.git] / plugins / IntelliLang / src / org / intellij / plugins / intelliLang / util / ShiftTabAction.java
blob19db6b05b77adc14e7bb67cfd6782d8827641db9
1 /*
2 * Copyright 2006 Sascha Weinreuter
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.intellij.plugins.intelliLang.util;
18 import com.intellij.openapi.actionSystem.AnAction;
19 import com.intellij.openapi.actionSystem.AnActionEvent;
20 import com.intellij.openapi.actionSystem.CustomShortcutSet;
21 import com.intellij.ui.EditorTextField;
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.event.InputEvent;
26 import java.awt.event.KeyEvent;
28 /**
29 * Provides Shift-Tab support in EditorTextFields which otherwise don't support this keystroke to
30 * move the input focus to the previous component.
32 @SuppressWarnings({"ComponentNotRegistered"})
33 public class ShiftTabAction extends AnAction {
34 private static final CustomShortcutSet SHIFT_TAB;
36 static {
37 final KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
38 SHIFT_TAB = new CustomShortcutSet(keyStroke);
41 private final EditorTextField myEditor;
43 private ShiftTabAction(EditorTextField editor) {
44 super("Shift-Tab");
45 myEditor = editor;
48 public void actionPerformed(AnActionEvent event) {
49 Container container = myEditor.getParent();
50 while (container != null && container.getFocusTraversalPolicy() == null) {
51 container = container.getParent();
53 if (container != null) {
54 final FocusTraversalPolicy ftp = container.getFocusTraversalPolicy();
55 if (ftp != null) {
56 final Component prev = ftp.getComponentBefore(container, myEditor);
57 if (prev != null) {
58 prev.requestFocus();
64 /**
65 * Call this method to enable Sift-Tab support for the supplied EditorTextField.
67 public static void attachTo(EditorTextField textField) {
68 // TODO following code seems not needed due to textField.pleaseHandleShiftTab()
69 new ShiftTabAction(textField).registerCustomShortcutSet(SHIFT_TAB, textField);