update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / actions / AbstractGuiEditorAction.java
blob0876bb1a951e5c1011e14e75376e1fdb087aac81
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.actionSystem.AnAction;
20 import com.intellij.openapi.actionSystem.AnActionEvent;
21 import com.intellij.openapi.command.CommandProcessor;
22 import com.intellij.uiDesigner.FormEditingUtil;
23 import com.intellij.uiDesigner.radComponents.RadComponent;
24 import com.intellij.uiDesigner.designSurface.GuiEditor;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
28 import java.util.ArrayList;
29 import java.util.List;
31 /**
32 * @author yole
34 public abstract class AbstractGuiEditorAction extends AnAction {
35 private final boolean myModifying;
37 protected AbstractGuiEditorAction() {
38 myModifying = false;
41 protected AbstractGuiEditorAction(final boolean modifying) {
42 myModifying = modifying;
45 public final void actionPerformed(final AnActionEvent e) {
46 final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
47 if (editor != null) {
48 final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
49 if (myModifying) {
50 if (!editor.ensureEditable()) return;
52 Runnable runnable = new Runnable() {
53 public void run() {
54 actionPerformed(editor, selection, e);
55 if (myModifying) {
56 editor.refreshAndSave(true);
60 if (getCommandName() != null) {
61 CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, getCommandName(), null);
63 else {
64 runnable.run();
69 protected abstract void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e);
71 public final void update(AnActionEvent e) {
72 GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
73 if (editor == null) {
74 e.getPresentation().setVisible(false);
75 e.getPresentation().setEnabled(false);
77 else {
78 e.getPresentation().setVisible(true);
79 e.getPresentation().setEnabled(true);
80 final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
81 update(editor, selection, e);
85 protected void update(@NotNull GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) {
88 @Nullable
89 protected String getCommandName() {
90 return null;