update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / palette / EditComponentAction.java
blob1c208d02babc201196d4a0ae4123f71d242913f8
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.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;
27 import java.awt.*;
29 /**
30 * @author yole
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()) {
39 return;
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"));
46 dialog.show();
47 if(!dialog.isOK()) {
48 return;
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())){
56 return;
58 if (group.containsItemClass(selectedItem.getClassName())) {
59 groupItem = group;
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 &&
74 groupItem != null &&
75 !selectedItem.isAnyComponent() &&
76 !selectedItem.isSpacer());