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
.palette
;
19 import com
.intellij
.openapi
.actionSystem
.AnAction
;
20 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
21 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
22 import com
.intellij
.openapi
.diagnostic
.Logger
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.openapi
.wm
.WindowManager
;
25 import com
.intellij
.uiDesigner
.UIDesignerBundle
;
32 public class EditComponentAction
extends AnAction
{
33 private static final Logger LOG
= Logger
.getInstance("#com.intellij.uiDesigner.palette.EditComponentAction");
35 public void actionPerformed(AnActionEvent e
) {
36 Project project
= e
.getData(PlatformDataKeys
.PROJECT
);
37 ComponentItem selectedItem
= e
.getData(ComponentItem
.DATA_KEY
);
38 if (project
== null || selectedItem
== null || selectedItem
.isAnyComponent() || selectedItem
.isSpacer()) {
42 final ComponentItem itemToBeEdited
= selectedItem
.clone(); /*"Cancel" should work, so we need edit copy*/
43 Window parentWindow
= WindowManager
.getInstance().suggestParentWindow(project
);
44 final ComponentItemDialog dialog
= new ComponentItemDialog(project
, parentWindow
, itemToBeEdited
, false);
45 dialog
.setTitle(UIDesignerBundle
.message("title.edit.component"));
51 GroupItem groupItem
= null;
52 Palette palette
= Palette
.getInstance(project
);
53 // If the itemToBeAdded is already in palette do nothing
54 for(GroupItem group
: palette
.getGroups()) {
55 if (group
.containsItemCopy(selectedItem
, itemToBeEdited
.getClassName())){
58 if (group
.containsItemClass(selectedItem
.getClassName())) {
62 LOG
.assertTrue(groupItem
!= null);
64 palette
.replaceItem(groupItem
, selectedItem
, itemToBeEdited
);
65 palette
.fireGroupsChanged();
68 @Override public void update(AnActionEvent e
) {
69 Project project
= e
.getData(PlatformDataKeys
.PROJECT
);
70 ComponentItem selectedItem
= e
.getData(ComponentItem
.DATA_KEY
);
71 GroupItem groupItem
= e
.getData(GroupItem
.DATA_KEY
);
72 e
.getPresentation().setEnabled(project
!= null &&
73 selectedItem
!= null &&
75 !selectedItem
.isAnyComponent() &&
76 !selectedItem
.isSpacer());