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
;
34 public abstract class AbstractGuiEditorAction
extends AnAction
{
35 private final boolean myModifying
;
37 protected AbstractGuiEditorAction() {
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());
48 final ArrayList
<RadComponent
> selection
= FormEditingUtil
.getSelectedComponents(editor
);
50 if (!editor
.ensureEditable()) return;
52 Runnable runnable
= new Runnable() {
54 actionPerformed(editor
, selection
, e
);
56 editor
.refreshAndSave(true);
60 if (getCommandName() != null) {
61 CommandProcessor
.getInstance().executeCommand(editor
.getProject(), runnable
, getCommandName(), null);
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());
74 e
.getPresentation().setVisible(false);
75 e
.getPresentation().setEnabled(false);
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
) {
89 protected String
getCommandName() {