Search in sources :

Example 26 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class ArchiveDiffTool method canShow.

@Override
public boolean canShow(DiffRequest request) {
    final DiffContent[] contents = request.getContents();
    final DialogWrapper instance = DialogWrapper.findInstance(IdeFocusManager.getInstance(request.getProject()).getFocusOwner());
    if (instance != null && instance.isModal())
        return false;
    if (contents.length == 2) {
        final VirtualFile file1 = contents[0].getFile();
        final VirtualFile file2 = contents[1].getFile();
        if (file1 != null && file2 != null) {
            final FileType type1 = contents[0].getContentType();
            final FileType type2 = contents[1].getContentType();
            return type1 == type2 && type1 instanceof ArchiveFileType;
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) FileType(com.intellij.openapi.fileTypes.FileType) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 27 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class IdeaDialogFixture method getDialogWrapperFrom.

@Nullable
protected static <T extends DialogWrapper> T getDialogWrapperFrom(@NotNull JDialog dialog, Class<T> dialogWrapperType) {
    try {
        WeakReference<DialogWrapper> dialogWrapperRef = field("myDialogWrapper").ofType(new TypeRef<WeakReference<DialogWrapper>>() {
        }).in(dialog).get();
        assertNotNull(dialogWrapperRef);
        DialogWrapper wrapper = dialogWrapperRef.get();
        if (dialogWrapperType.isInstance(wrapper)) {
            return dialogWrapperType.cast(wrapper);
        }
    } catch (ReflectionError ignored) {
    }
    return null;
}
Also used : ReflectionError(org.fest.reflect.exception.ReflectionError) WeakReference(java.lang.ref.WeakReference) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class AbstractModuleDataService method ruleOrphanModules.

/**
   * There is a possible case that an external module has been un-linked from ide project. There are two ways to process
   * ide modules which correspond to that external project:
   * <pre>
   * <ol>
   *   <li>Remove them from ide project as well;</li>
   *   <li>Keep them at ide project as well;</li>
   * </ol>
   * </pre>
   * This method handles that situation, i.e. it asks a user what should be done and acts accordingly.
   *
   * @param orphanModules    modules which correspond to the un-linked external project
   * @param project          current ide project
   * @param externalSystemId id of the external system which project has been un-linked from ide project
   */
private static void ruleOrphanModules(@NotNull final List<Module> orphanModules, @NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @NotNull final Consumer<List<Module>> result) {
    ExternalSystemApiUtil.executeOnEdt(true, () -> {
        List<Module> toRemove = ContainerUtil.newSmartList();
        if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
            toRemove.addAll(orphanModules);
        } else {
            final JPanel content = new JPanel(new GridBagLayout());
            content.add(new JLabel(ExternalSystemBundle.message("orphan.modules.text", externalSystemId.getReadableName())), ExternalSystemUiUtil.getFillLineConstraints(0));
            final CheckBoxList<Module> orphanModulesList = new CheckBoxList<>();
            orphanModulesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            orphanModulesList.setItems(orphanModules, module -> module.getName());
            for (Module module : orphanModules) {
                orphanModulesList.setItemSelected(module, true);
            }
            orphanModulesList.setBorder(IdeBorderFactory.createEmptyBorder(8));
            content.add(orphanModulesList, ExternalSystemUiUtil.getFillLineConstraints(0));
            content.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 8, 0));
            DialogWrapper dialog = new DialogWrapper(project) {

                {
                    setTitle(ExternalSystemBundle.message("import.title", externalSystemId.getReadableName()));
                    init();
                }

                @Nullable
                @Override
                protected JComponent createCenterPanel() {
                    return new JBScrollPane(content);
                }

                @NotNull
                protected Action[] createActions() {
                    return new Action[] { getOKAction() };
                }
            };
            dialog.showAndGet();
            for (int i = 0; i < orphanModules.size(); i++) {
                Module module = orphanModules.get(i);
                if (orphanModulesList.isItemSelected(i)) {
                    toRemove.add(module);
                }
            }
        }
        result.consume(toRemove);
    });
}
Also used : CheckBoxList(com.intellij.ui.CheckBoxList) Module(com.intellij.openapi.module.Module) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 29 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class ExtractMethodObjectProcessor method moveUsedMethodsToInner.

void moveUsedMethodsToInner() {
    if (!myUsages.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            WriteAction.run(() -> {
                for (MethodToMoveUsageInfo usage : myUsages) {
                    final PsiMember member = (PsiMember) usage.getElement();
                    LOG.assertTrue(member != null);
                    myInnerClass.add(member.copy());
                    member.delete();
                }
            });
            return;
        }
        final List<MemberInfo> memberInfos = new ArrayList<>();
        for (MethodToMoveUsageInfo usage : myUsages) {
            memberInfos.add(new MemberInfo((PsiMethod) usage.getElement()));
        }
        final MemberSelectionPanel panel = new MemberSelectionPanel("&Methods to move to the extracted class", memberInfos, null);
        DialogWrapper dlg = new DialogWrapper(myProject, false) {

            {
                init();
                setTitle("Move Methods Used in Extracted Block Only");
            }

            @Override
            protected JComponent createCenterPanel() {
                return panel;
            }
        };
        if (dlg.showAndGet()) {
            WriteAction.run(() -> {
                for (MemberInfoBase<PsiMember> memberInfo : panel.getTable().getSelectedMemberInfos()) {
                    if (memberInfo.isChecked()) {
                        myInnerClass.add(memberInfo.getMember().copy());
                        memberInfo.getMember().delete();
                    }
                }
            });
        }
    }
}
Also used : MemberInfo(com.intellij.refactoring.util.classMembers.MemberInfo) MemberSelectionPanel(com.intellij.refactoring.ui.MemberSelectionPanel) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 30 with DialogWrapper

use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.

the class CreateDialogAction method invokeDialog.

@NotNull
protected PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) {
    final MyInputValidator validator = new JavaNameValidator(project, directory);
    final MyContentPane contentPane = new MyContentPane();
    final DialogWrapper dialog = new DialogWrapper(project, true) {

        {
            init();
            setTitle(UIDesignerBundle.message("title.new.dialog"));
        }

        protected JComponent createCenterPanel() {
            return contentPane.getPanel();
        }

        protected void doOKAction() {
            myRecentGenerateOK = contentPane.myChkGenerateOK.isSelected();
            myRecentGenerateCancel = contentPane.myChkGenerateCancel.isSelected();
            myRecentGenerateMain = contentPane.myChkGenerateMain.isSelected();
            final String inputString = contentPane.myTfClassName.getText().trim();
            if (validator.checkInput(inputString) && validator.canClose(inputString)) {
                close(OK_EXIT_CODE);
            }
        }

        public JComponent getPreferredFocusedComponent() {
            return contentPane.myTfClassName;
        }
    };
    dialog.show();
    return validator.getCreatedElements();
}
Also used : DialogWrapper(com.intellij.openapi.ui.DialogWrapper) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DialogWrapper (com.intellij.openapi.ui.DialogWrapper)37 Project (com.intellij.openapi.project.Project)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 ActionEvent (java.awt.event.ActionEvent)6 Nullable (org.jetbrains.annotations.Nullable)6 JBScrollPane (com.intellij.ui.components.JBScrollPane)5 ActionListener (java.awt.event.ActionListener)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 Document (com.intellij.openapi.editor.Document)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MockDocument (com.intellij.mock.MockDocument)2 MockPsiFile (com.intellij.mock.MockPsiFile)2 javax.swing (javax.swing)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 AnnotationTargetUtil (com.intellij.codeInsight.AnnotationTargetUtil)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)1