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
;
31 import java
.util
.ArrayList
;
32 import java
.util
.Collections
;
33 import java
.util
.List
;
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());
57 public List
<ComponentItem
> getValues() {
61 public boolean isSelectable(final ComponentItem value
) {
65 public Icon
getIconFor(final ComponentItem aValue
) {
66 return aValue
.getSmallIcon();
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
) {
81 public int getDefaultOptionIndex() {
82 if (myInitialSelection
!= null) {
83 int index
= myItems
.indexOf(myInitialSelection
);
91 public String
getTitle() {
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
) {
104 public void canceled() {
107 public boolean isMnemonicsNavigationEnabled() {
111 public MnemonicNavigationFilter
<ComponentItem
> getMnemonicNavigationFilter() {
115 public boolean isSpeedSearchEnabled() {
119 public boolean isAutoSelectionEnabled() {
123 public SpeedSearchFilter
<ComponentItem
> getSpeedSearchFilter() {
127 public boolean canBeHidden(final ComponentItem value
) {
131 public String
getIndexedString(final ComponentItem value
) {
132 if (value
.isAnyComponent()) {
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
);
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) {