Search in sources :

Example 1 with LabeledComponent

use of com.intellij.openapi.ui.LabeledComponent in project intellij-plugins by StepicOrg.

the class StepikPyProjectGenerator method getLocationField.

@Nullable
private TextFieldWithBrowseButton getLocationField() {
    if (locationField == null) {
        Container basePanel = wizardStep.getComponent().getParent();
        if (basePanel == null) {
            return null;
        }
        try {
            Container topPanel = (Container) basePanel.getComponent(0);
            LabeledComponent locationComponent = (LabeledComponent) topPanel.getComponent(0);
            locationField = (TextFieldWithBrowseButton) locationComponent.getComponent();
        } catch (ClassCastException | ArrayIndexOutOfBoundsException e) {
            logger.warn("Auto naming for a project don't work: ", e);
            return null;
        }
    }
    return locationField;
}
Also used : LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with LabeledComponent

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

the class GenerateVisitorByHierarchyAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Ref<String> visitorNameRef = Ref.create("MyVisitor");
    final Ref<PsiClass> parentClassRef = Ref.create(null);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final PsiNameHelper helper = PsiNameHelper.getInstance(project);
    final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {

        @Override
        protected ValidationInfo doValidate() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            if (!helper.isQualifiedName(visitorNameRef.get())) {
                return new ValidationInfo("Visitor class name is not valid");
            } else if (parentClassRef.isNull()) {
                return new ValidationInfo("Hierarchy root class should be specified");
            } else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
                return new ValidationInfo("Hierarchy root class should be an interface or a class");
            }
            return super.doValidate();
        }

        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(super.createCenterPanel(), BorderLayout.CENTER);
            panel.add(createNamePanel(), BorderLayout.NORTH);
            panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
            return panel;
        }

        private JComponent createNamePanel() {
            LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Visitor class");
            final JTextField nameField = new JTextField(visitorNameRef.get());
            labeledComponent.setComponent(nameField);
            nameField.getDocument().addDocumentListener(new DocumentAdapter() {

                protected void textChanged(final DocumentEvent e) {
                    visitorNameRef.set(nameField.getText());
                }
            });
            return labeledComponent;
        }

        private JComponent createBaseClassPanel() {
            LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Hierarchy root class");
            final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
            final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
            final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
            final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
            labeledComponent.setComponent(editorTextField);
            editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

                public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
                    parentClassRef.set(null);
                    try {
                        final PsiType psiType = codeFragment.getType();
                        final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
                        parentClassRef.set(psiClass);
                    } catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
                    // ok
                    }
                }
            });
            return labeledComponent;
        }
    };
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
    if (element instanceof PsiPackage) {
        dialog.selectPackage(((PsiPackage) element).getQualifiedName());
    } else if (element instanceof PsiDirectory) {
        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
        if (aPackage != null) {
            dialog.selectPackage(aPackage.getQualifiedName());
        }
    }
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
        return;
    }
    final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
    final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
    if (ideView != null && visitorClass != null) {
        ideView.selectElement(visitorClass);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) IdeView(com.intellij.ide.IdeView) EditorTextField(com.intellij.ui.EditorTextField) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Project(com.intellij.openapi.project.Project) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) PackageChooserDialog(com.intellij.ide.util.PackageChooserDialog)

Example 3 with LabeledComponent

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

the class ConfigurationsTest method testEditJUnitConfiguration.

public void testEditJUnitConfiguration() throws ConfigurationException {
    if (PlatformTestUtil.COVERAGE_ENABLED_BUILD)
        return;
    PsiClass testA = findTestA(getModule2());
    JUnitConfiguration configuration = createConfiguration(testA);
    JUnitConfigurable editor = new JUnitConfigurable(myProject);
    try {
        Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
        configurable.reset();
        final EditorTextFieldWithBrowseButton component = ((LabeledComponent<EditorTextFieldWithBrowseButton>) editor.getTestLocation(JUnitConfigurationModel.CLASS)).getComponent();
        assertEquals(testA.getQualifiedName(), component.getText());
        PsiClass otherTest = findClass(getModule2(), "test2.Test2");
        component.setText(otherTest.getQualifiedName());
        configurable.apply();
        assertEquals(otherTest.getName(), configuration.getName());
        String specialName = "My name";
        configuration.setName(specialName);
        configuration.setNameChangedByUser(true);
        configurable.reset();
        component.setText(testA.getQualifiedName());
        configurable.apply();
        assertEquals(specialName, configuration.getName());
    } finally {
        Disposer.dispose(editor);
    }
}
Also used : EditorTextFieldWithBrowseButton(com.intellij.ui.EditorTextFieldWithBrowseButton) JUnitConfigurable(com.intellij.execution.junit2.configuration.JUnitConfigurable) Configurable(com.intellij.openapi.options.Configurable) ApplicationConfigurable(com.intellij.execution.application.ApplicationConfigurable) JUnitConfigurable(com.intellij.execution.junit2.configuration.JUnitConfigurable) LabeledComponent(com.intellij.openapi.ui.LabeledComponent)

Example 4 with LabeledComponent

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

the class MergePanel2 method setDiffRequest.

public void setDiffRequest(DiffRequest data) {
    setTitle(data.getWindowTitle());
    disposeMergeList();
    for (int i = 0; i < EDITORS_COUNT; i++) {
        getEditorPlace(i).setDocument(null);
    }
    LOG.assertTrue(!myDuringCreation);
    myDuringCreation = true;
    myProvider.putData(data.getGenericData());
    try {
        myData = data;
        String[] titles = myData.getContentTitles();
        for (int i = 0; i < myEditorsPanels.length; i++) {
            LabeledComponent editorsPanel = myEditorsPanels[i];
            editorsPanel.getLabel().setText(titles[i].isEmpty() ? " " : titles[i]);
        }
        createMergeList();
        data.customizeToolbar(myPanel.resetToolbar());
        myPanel.registerToolbarActions();
        if (data instanceof MergeRequestImpl && myBuilder != null) {
            Convertor<DialogWrapper, Boolean> preOkHook = new Convertor<DialogWrapper, Boolean>() {

                @Override
                public Boolean convert(DialogWrapper dialog) {
                    ChangeCounter counter = ChangeCounter.getOrCreate(myMergeList);
                    int changes = counter.getChangeCounter();
                    int conflicts = counter.getConflictCounter();
                    if (changes == 0 && conflicts == 0)
                        return true;
                    return Messages.showYesNoDialog(dialog.getRootPane(), DiffBundle.message("merge.dialog.apply.partially.resolved.changes.confirmation.message", changes, conflicts), DiffBundle.message("apply.partially.resolved.merge.dialog.title"), Messages.getQuestionIcon()) == Messages.YES;
                }
            };
            ((MergeRequestImpl) data).setActions(myBuilder, this, preOkHook);
        }
    } finally {
        myDuringCreation = false;
    }
}
Also used : MergeRequestImpl(com.intellij.openapi.diff.impl.mergeTool.MergeRequestImpl) ChangeCounter(com.intellij.openapi.diff.impl.incrementalMerge.ChangeCounter) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) DiffDividerPaint(com.intellij.openapi.diff.impl.splitter.DiffDividerPaint) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Convertor(com.intellij.util.containers.Convertor)

Example 5 with LabeledComponent

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

the class ProjectSettingsPanel method getMainComponent.

public JComponent getMainComponent() {
    final LabeledComponent<JComboBox> component = new LabeledComponent<>();
    component.setText("Default &project copyright:");
    component.setLabelLocation(BorderLayout.WEST);
    component.setComponent(myProfilesComboBox);
    ElementProducer<ScopeSetting> producer = new ElementProducer<ScopeSetting>() {

        @Override
        public ScopeSetting createElement() {
            return new ScopeSetting(CustomScopesProviderEx.getAllScope(), myProfilesModel.getAllProfiles().values().iterator().next());
        }

        @Override
        public boolean canCreateElement() {
            return !myProfilesModel.getAllProfiles().isEmpty();
        }
    };
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myScopeMappingTable, producer);
    return JBUI.Panels.simplePanel(0, 10).addToTop(component).addToCenter(decorator.createPanel()).addToBottom(myScopesLink);
}
Also used : ToolbarDecorator(com.intellij.ui.ToolbarDecorator) LabeledComponent(com.intellij.openapi.ui.LabeledComponent)

Aggregations

LabeledComponent (com.intellij.openapi.ui.LabeledComponent)6 DocumentAdapter (com.intellij.ui.DocumentAdapter)2 DocumentEvent (javax.swing.event.DocumentEvent)2 Nullable (org.jetbrains.annotations.Nullable)2 ApplicationConfigurable (com.intellij.execution.application.ApplicationConfigurable)1 JUnitConfigurable (com.intellij.execution.junit2.configuration.JUnitConfigurable)1 IdeView (com.intellij.ide.IdeView)1 PackageChooserDialog (com.intellij.ide.util.PackageChooserDialog)1 ChangeCounter (com.intellij.openapi.diff.impl.incrementalMerge.ChangeCounter)1 MergeRequestImpl (com.intellij.openapi.diff.impl.mergeTool.MergeRequestImpl)1 DiffDividerPaint (com.intellij.openapi.diff.impl.splitter.DiffDividerPaint)1 Document (com.intellij.openapi.editor.Document)1 Configurable (com.intellij.openapi.options.Configurable)1 Project (com.intellij.openapi.project.Project)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 EditorTextField (com.intellij.ui.EditorTextField)1 EditorTextFieldWithBrowseButton (com.intellij.ui.EditorTextFieldWithBrowseButton)1 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)1 Convertor (com.intellij.util.containers.Convertor)1