Example usage for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton

List of usage examples for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton

Introduction

In this page you can find the example usage for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton.

Prototype

public TextFieldWithBrowseButton() 

Source Link

Usage

From source file:com.hp.alm.ali.idea.ui.editor.field.ReferenceField.java

License:Apache License

public ReferenceField(final Project project, final Field field, Context context, boolean editable) {
    super(field.getLabel(), field.isRequired(), context.getEntity().getPropertyValue(field.getName()));

    this.field = field;

    translateService = project.getComponent(TranslateService.class);

    Entity entity = context.getEntity();
    selectedId = getOriginalValue();/* www . ja  v a  2  s.c  om*/

    textFieldWithBrowseButton = new TextFieldWithBrowseButton();
    textFieldWithBrowseButton.getTextField().setEditable(editable);
    textFieldWithBrowseButton.setEnabled(editable);

    String value = entity.getPropertyValue(field.getName());
    isCompound = translateService.isTranslated(field);
    if (isCompound && !value.isEmpty()) {
        translateService.translateAsync(field, value, true, new ValueCallback() {
            @Override
            public void value(String value) {
                textFieldWithBrowseButton.getTextField().setText(value);
            }
        });
    } else {
        textFieldWithBrowseButton.getTextField().setText(value);
    }

    if (editable) {
        FilterFactory filterFactory = project.getComponent(FilterManager.class).getFilterFactory(context,
                entity.getType(), field, false);
        if (filterFactory == null) {
            String target = field.resolveReference(entity);
            filterFactory = new FilterFactoryImpl(project, target, false, true);
        }

        textFieldWithBrowseButton.setEditable(!isCompound);
        if (textFieldWithBrowseButton.isEditable()) {
            UndoAction.installUndoRedoSupport(textFieldWithBrowseButton.getTextField());
        }
        final FilterFactory factory = filterFactory;
        textFieldWithBrowseButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                FilterChooser chooser = factory.createChooser(selectedId);
                chooser.show();
                selectedId = chooser.getSelectedValue();
                selectIdUpdated();
            }
        });
        textFieldWithBrowseButton.getTextField().getDocument()
                .addDocumentListener(new MyDocumentListener(this) {
                    protected void updated() {
                        if (!isCompound) {
                            selectedId = textFieldWithBrowseButton.getText();
                        }
                        super.updated();
                    }
                });
    }
}

From source file:com.hp.alm.ali.idea.ui.editor.field.UploadField.java

License:Apache License

public UploadField(String label, boolean required, boolean editable) {
    super(label, required, "");

    textFieldWithBrowseButton = new TextFieldWithBrowseButton();
    textFieldWithBrowseButton.getTextField().setEditable(false);
    textFieldWithBrowseButton.getTextField().getDocument().addDocumentListener(new MyDocumentListener(this));

    if (editable) {
        textFieldWithBrowseButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                VirtualFile[] file = FileChooser.chooseFiles(
                        new FileChooserDescriptor(true, false, true, true, false, false),
                        textFieldWithBrowseButton.getTextField(), null, lastDir);
                if (file.length > 0) {
                    textFieldWithBrowseButton.getTextField().setText(file[0].getPath());
                    lastDir = file[0].getParent();
                }//  w w w  .j  ava2  s.  c  o  m
            }
        });
    } else {
        textFieldWithBrowseButton.setEnabled(false);
    }
}

From source file:com.intellij.android.designer.propertyTable.editors.ResourceEditor.java

License:Apache License

public ResourceEditor(ResourceType[] types, Set<AttributeFormat> formats, String[] values) {
    myTypes = types;/*from  www .j  a v a2s  .co  m*/
    myIsDimension = formats.contains(AttributeFormat.Dimension);

    if (formats.contains(AttributeFormat.Boolean)) {
        myCheckBox = new JCheckBox();
        myEditor = new ComponentWithBrowseButton<JCheckBox>(myCheckBox, null) {
            @Override
            public Dimension getPreferredSize() {
                return getComponentPreferredSize();
            }
        };
        myCheckBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (!myIgnoreCheckBoxValue) {
                    myBooleanResourceValue = null;
                    fireValueCommitted(true, true);
                }
            }
        });
    } else if (formats.contains(AttributeFormat.Enum)) {
        ComboboxWithBrowseButton editor = new ComboboxWithBrowseButton(
                SystemInfo.isWindows ? new MyComboBox() : new JComboBox()) {
            @Override
            public Dimension getPreferredSize() {
                return getComponentPreferredSize();
            }
        };

        final JComboBox comboBox = editor.getComboBox();
        DefaultComboBoxModel model = new DefaultComboBoxModel(values);
        model.insertElementAt(StringsComboEditor.UNSET, 0);
        comboBox.setModel(model);
        comboBox.setEditable(true);
        ComboEditor.installListeners(comboBox, new ComboEditor.ComboEditorListener(this) {
            @Override
            protected void onValueChosen() {
                if (comboBox.getSelectedItem() == StringsComboEditor.UNSET) {
                    comboBox.setSelectedItem(null);
                }
                super.onValueChosen();
            }
        });
        myEditor = editor;
        comboBox.setSelectedIndex(0);
    } else {
        myEditor = new TextFieldWithBrowseButton() {
            @Override
            protected void installPathCompletion(FileChooserDescriptor fileChooserDescriptor,
                    @Nullable Disposable parent) {
            }

            @Override
            public Dimension getPreferredSize() {
                return getComponentPreferredSize();
            }
        };
        myEditor.registerKeyboardAction(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

        JTextField textField = getComboText();
        textField.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                fireValueCommitted(true, true);
            }
        });
        textField.getDocument().addDocumentListener(new DocumentAdapter() {
            @Override
            protected void textChanged(final DocumentEvent e) {
                preferredSizeChanged();
            }
        });
    }

    if (myCheckBox == null) {
        myEditor.registerKeyboardAction(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    myEditor.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showDialog();
        }
    });
    myEditor.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            myEditor.getChildComponent().requestFocus();
        }
    });
}

From source file:com.intellij.codeInspection.export.ExportToHTMLDialog.java

License:Apache License

@Override
protected JComponent createNorthPanel() {
    OptionGroup optionGroup = new OptionGroup();

    myTargetDirectoryField = new TextFieldWithBrowseButton();
    optionGroup.add(//from   ww  w. j a  v a 2  s .c  o  m
            com.intellij.codeEditor.printing.ExportToHTMLDialog.assignLabel(myTargetDirectoryField, myProject));

    return optionGroup.createPanel();
}

From source file:com.intellij.debugger.ui.ExportDialog.java

License:Apache License

protected JComponent createNorthPanel() {
    JPanel box = new JPanel(new BorderLayout());
    box.add(new JLabel(DebuggerBundle.message("label.threads.export.dialog.file")), BorderLayout.WEST);
    myTfFilePath = new TextFieldWithBrowseButton();
    myTfFilePath.addBrowseFolderListener(null, null, myProject,
            FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
    box.add(myTfFilePath, BorderLayout.CENTER);
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(box, BorderLayout.CENTER);
    panel.add(Box.createVerticalStrut(7), BorderLayout.SOUTH);
    return panel;
}

From source file:com.intellij.execution.configuration.EnvironmentVariablesComponent.java

License:Apache License

public EnvironmentVariablesComponent() {
    super();//from  w w  w .j  a  v  a 2  s .c om
    final TextFieldWithBrowseButton envsTestField = new TextFieldWithBrowseButton();
    envsTestField.setEditable(false);
    setComponent(envsTestField);
    setText(ExecutionBundle.message("environment.variables.component.title"));
    getComponent().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            new MyEnvironmentVariablesDialog().show();
        }
    });
}

From source file:com.intellij.execution.jar.JarApplicationConfigurable.java

License:Apache License

private void createUIComponents() {
    myJarPathComponent = new LabeledComponent<TextFieldWithBrowseButton>();
    TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton();
    textFieldWithBrowseButton.addBrowseFolderListener("Choose JAR File", null, myProject,
            new FileChooserDescriptor(false, false, true, true, false, false));
    myJarPathComponent.setComponent(textFieldWithBrowseButton);
}

From source file:com.intellij.execution.junit2.configuration.JUnitConfigurable.java

License:Apache License

public JUnitConfigurable(final Project project) {
    myProject = project;//from w ww  .j  ava 2s . co  m
    myModel = new JUnitConfigurationModel(project);
    myModuleSelector = new ConfigurationModuleSelector(project, getModulesComponent());
    myCommonJavaParameters.setModuleContext(myModuleSelector.getModule());
    myModule.getComponent().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myCommonJavaParameters.setModuleContext(myModuleSelector.getModule());
        }
    });
    myBrowsers = new BrowseModuleValueActionListener[] { new PackageChooserActionListener(project),
            new TestClassBrowser(project), new MethodBrowser(project), new TestsChooserActionListener(project),
            new BrowseModuleValueActionListener(project) {
                @Override
                protected String showDialog() {
                    final VirtualFile virtualFile = FileChooser.chooseFile(
                            FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, null);
                    if (virtualFile != null) {
                        return FileUtil.toSystemDependentName(virtualFile.getPath());
                    }
                    return null;
                }
            } };
    // Garbage support
    final DefaultComboBoxModel aModel = new DefaultComboBoxModel();
    aModel.addElement(JUnitConfigurationModel.ALL_IN_PACKAGE);
    aModel.addElement(JUnitConfigurationModel.DIR);
    aModel.addElement(JUnitConfigurationModel.PATTERN);
    aModel.addElement(JUnitConfigurationModel.CLASS);
    aModel.addElement(JUnitConfigurationModel.METHOD);
    myTypeChooser.setModel(aModel);
    myTypeChooser.setRenderer(new ListCellRendererWrapper<Integer>() {
        @Override
        public void customize(JList list, Integer value, int index, boolean selected, boolean hasFocus) {
            switch (value) {
            case JUnitConfigurationModel.ALL_IN_PACKAGE:
                setText("All in package");
                break;
            case JUnitConfigurationModel.DIR:
                setText("All in directory");
                break;
            case JUnitConfigurationModel.PATTERN:
                setText("Pattern");
                break;
            case JUnitConfigurationModel.CLASS:
                setText("Class");
                break;
            case JUnitConfigurationModel.METHOD:
                setText("Method");
                break;
            }
        }
    });

    myTestLocations[JUnitConfigurationModel.ALL_IN_PACKAGE] = myPackage;
    myTestLocations[JUnitConfigurationModel.CLASS] = myClass;
    myTestLocations[JUnitConfigurationModel.METHOD] = myMethod;
    myTestLocations[JUnitConfigurationModel.DIR] = myDir;

    final JPanel panel = myPattern.getComponent();
    panel.setLayout(new BorderLayout());
    myPatternTextField = new TextFieldWithBrowseButton();
    myPatternTextField.setButtonIcon(IconUtil.getAddIcon());
    panel.add(myPatternTextField, BorderLayout.CENTER);
    final FixedSizeButton editBtn = new FixedSizeButton();
    editBtn.setIcon(AllIcons.Actions.ShowViewer);
    editBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Messages.showTextAreaDialog(myPatternTextField.getTextField(), "Configure suite tests",
                    "EditParametersPopupWindow");
        }
    });
    panel.add(editBtn, BorderLayout.EAST);
    myTestLocations[JUnitConfigurationModel.PATTERN] = myPattern;

    final FileChooserDescriptor dirFileChooser = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    dirFileChooser.setHideIgnored(false);
    final JTextField textField = myDir.getComponent().getTextField();
    InsertPathAction.addTo(textField, dirFileChooser);
    FileChooserFactory.getInstance().installFileCompletion(textField, dirFileChooser, true, null);
    // Done

    myModel.setListener(this);

    myTypeChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final Object selectedItem = myTypeChooser.getSelectedItem();
            myModel.setType((Integer) selectedItem);
            changePanel();
        }
    });
    myModel.setType(JUnitConfigurationModel.CLASS);
    installDocuments();
    addRadioButtonsListeners(new JRadioButton[] { myWholeProjectScope, mySingleModuleScope, myModuleWDScope },
            null);
    myWholeProjectScope.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent e) {
            onScopeChanged();
        }
    });

    myCommonJavaParameters.getProgramParametersComponent().setVisible(false);

    setAnchor(mySearchForTestsLabel);
    myModule.setAnchor(myAlternativeJREPanel.getCbEnabled());
    myCommonJavaParameters.setAnchor(myAlternativeJREPanel.getCbEnabled());
}

From source file:com.intellij.ide.ui.customization.CustomizableActionsPanel.java

License:Apache License

private static TextFieldWithBrowseButton createBrowseField() {
    TextFieldWithBrowseButton textField = new TextFieldWithBrowseButton();
    textField.setPreferredSize(new Dimension(200, textField.getPreferredSize().height));
    textField.setMinimumSize(new Dimension(200, textField.getPreferredSize().height));
    final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false,
            false, false) {/*from  w  ww  . ja  v  a 2  s .  c om*/
        public boolean isFileSelectable(VirtualFile file) {
            //noinspection HardCodedStringLiteral
            return file.getName().endsWith(".png");
        }
    };
    textField.addBrowseFolderListener(IdeBundle.message("title.browse.icon"),
            IdeBundle.message("prompt.browse.icon.for.selected.action"), null, fileChooserDescriptor);
    InsertPathAction.addTo(textField.getTextField(), fileChooserDescriptor);
    return textField;
}

From source file:com.intellij.ide.util.newProjectWizard.modes.CreateModuleFromSourcesMode.java

License:Apache License

@Override
public JComponent getAdditionalSettings(WizardContext wizardContext) {
    myPathPanel = new TextFieldWithBrowseButton();
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myPathPanel.addBrowseFolderListener("Select Directory Containing Module Files", null,
            wizardContext.getProject(), descriptor);
    onChosen(false);//www.  j  av a2 s.c  o  m
    return myPathPanel;
}