update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / actions / ReloadCustomComponentsAction.java
blob37218e054a4ea6685f198076fdb2b719ff4dd5b6
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.
18 * Created by IntelliJ IDEA.
19 * User: yole
20 * Date: 05.10.2006
21 * Time: 13:35:16
23 package com.intellij.uiDesigner.actions;
25 import com.intellij.openapi.actionSystem.AnAction;
26 import com.intellij.openapi.actionSystem.AnActionEvent;
27 import com.intellij.openapi.actionSystem.PlatformDataKeys;
28 import com.intellij.openapi.fileEditor.FileEditor;
29 import com.intellij.openapi.fileEditor.FileEditorManager;
30 import com.intellij.openapi.project.Project;
31 import com.intellij.openapi.util.Ref;
32 import com.intellij.uiDesigner.FormEditingUtil;
33 import com.intellij.uiDesigner.LoaderFactory;
34 import com.intellij.uiDesigner.designSurface.GuiEditor;
35 import com.intellij.uiDesigner.editor.UIFormEditor;
36 import com.intellij.uiDesigner.lw.IComponent;
37 import com.intellij.uiDesigner.radComponents.RadErrorComponent;
39 public class ReloadCustomComponentsAction extends AnAction {
40 public void actionPerformed(AnActionEvent e) {
41 Project project = e.getData(PlatformDataKeys.PROJECT);
42 if (project == null) return;
43 LoaderFactory.getInstance(project).clearClassLoaderCache();
44 final FileEditor[] fileEditors = FileEditorManager.getInstance(project).getAllEditors();
45 for(FileEditor editor: fileEditors) {
46 if (editor instanceof UIFormEditor) {
47 ((UIFormEditor) editor).getEditor().readFromFile(true);
52 @Override
53 public void update(AnActionEvent e) {
54 final GuiEditor editor = FormEditingUtil.getActiveEditor(e.getDataContext());
55 e.getPresentation().setVisible(editor != null && haveCustomComponents(editor));
58 private static boolean haveCustomComponents(final GuiEditor editor) {
59 // quick & dirty check
60 if (editor.isFormInvalid()) {
61 return true;
63 final Ref<Boolean> result = new Ref<Boolean>();
64 FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {
65 public boolean visit(final IComponent component) {
66 if (component instanceof RadErrorComponent || !component.getComponentClassName().startsWith("javax.swing")) {
67 result.set(Boolean.TRUE);
68 return false;
70 return true;
72 });
73 return !result.isNull();