update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / actions / PaletteListPopupStep.java
blob22b99c747b32c9487524e954ef57cf1354431691
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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.
17 package com.intellij.uiDesigner.actions;
19 import com.intellij.openapi.ui.popup.*;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.uiDesigner.UIDesignerBundle;
22 import com.intellij.uiDesigner.designSurface.GuiEditor;
23 import com.intellij.uiDesigner.designSurface.InsertComponentProcessor;
24 import com.intellij.uiDesigner.palette.ComponentItem;
25 import com.intellij.uiDesigner.palette.GroupItem;
26 import com.intellij.uiDesigner.palette.Palette;
27 import com.intellij.util.Processor;
28 import org.jetbrains.annotations.NotNull;
30 import javax.swing.*;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
35 /**
36 * @author yole
38 class PaletteListPopupStep implements ListPopupStep<ComponentItem>, SpeedSearchFilter<ComponentItem> {
39 private final ArrayList<ComponentItem> myItems = new ArrayList<ComponentItem>();
40 private final ComponentItem myInitialSelection;
41 private final Processor<ComponentItem> myRunnable;
42 private final String myTitle;
43 private final Project myProject;
45 PaletteListPopupStep(GuiEditor editor, ComponentItem initialSelection, final Processor<ComponentItem> runnable, final String title) {
46 myInitialSelection = initialSelection;
47 myRunnable = runnable;
48 myProject = editor.getProject();
49 Palette palette = Palette.getInstance(editor.getProject());
50 for(GroupItem group: palette.getToolWindowGroups()) {
51 Collections.addAll(myItems, group.getItems());
53 myTitle = title;
56 @NotNull
57 public List<ComponentItem> getValues() {
58 return myItems;
61 public boolean isSelectable(final ComponentItem value) {
62 return true;
65 public Icon getIconFor(final ComponentItem aValue) {
66 return aValue.getSmallIcon();
69 @NotNull
70 public String getTextFor(final ComponentItem value) {
71 if (value.isAnyComponent()) {
72 return UIDesignerBundle.message("palette.non.palette.component");
74 return value.getClassShortName();
77 public ListSeparator getSeparatorAbove(final ComponentItem value) {
78 return null;
81 public int getDefaultOptionIndex() {
82 if (myInitialSelection != null) {
83 int index = myItems.indexOf(myInitialSelection);
84 if (index >= 0) {
85 return index;
88 return 0;
91 public String getTitle() {
92 return myTitle;
95 public PopupStep onChosen(final ComponentItem selectedValue, final boolean finalChoice) {
96 myRunnable.process(selectedValue);
97 return PopupStep.FINAL_CHOICE;
100 public boolean hasSubstep(final ComponentItem selectedValue) {
101 return false;
104 public void canceled() {
107 public boolean isMnemonicsNavigationEnabled() {
108 return false;
111 public MnemonicNavigationFilter<ComponentItem> getMnemonicNavigationFilter() {
112 return null;
115 public boolean isSpeedSearchEnabled() {
116 return true;
119 public boolean isAutoSelectionEnabled() {
120 return false;
123 public SpeedSearchFilter<ComponentItem> getSpeedSearchFilter() {
124 return this;
127 public boolean canBeHidden(final ComponentItem value) {
128 return true;
131 public String getIndexedString(final ComponentItem value) {
132 if (value.isAnyComponent()) {
133 return "";
135 return value.getClassShortName();
138 public void hideComponentClass(final String componentClassName) {
139 for(ComponentItem item: myItems) {
140 if (item.getClassName().equals(componentClassName)) {
141 myItems.remove(item);
142 break;
147 public void hideNonAtomic() {
148 for(int i=myItems.size()-1; i >= 0; i--) {
149 ComponentItem item = myItems.get(i);
150 if (InsertComponentProcessor.getRadComponentFactory(myProject, item.getClassName()) != null || item.getBoundForm() != null) {
151 myItems.remove(i);