use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class PyUniversalTestForm method create.
/**
* @param configuration configuration to configure form on creation
* @param customOptions additional option names this form shall support. Make sure your configuration has appropriate properties.
*/
@NotNull
public static PyUniversalTestForm create(@NotNull final PyUniversalTestConfiguration configuration, @NotNull final CustomOption... customOptions) {
// TODO: DOC
final PyUniversalTestForm form = new PyUniversalTestForm();
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(PythonFileType.INSTANCE);
form.myTargetText.addBrowseFolderListener("Choose File or Folder", null, configuration.getProject(), descriptor);
for (final TestTargetType testTargetType : TestTargetType.values()) {
final JBRadioButton button = new JBRadioButton(StringUtil.capitalize(testTargetType.name().toLowerCase(Locale.getDefault())));
button.setActionCommand(testTargetType.name());
button.addActionListener(o -> form.configureElementsVisibility());
form.myButtonGroup.add(button);
form.myTargets.add(button);
}
form.myButtonGroup.getElements().nextElement().setSelected(true);
form.myOptionsForm = PyCommonOptionsFormFactory.getInstance().createForm(configuration.getCommonOptionsFormData());
final GridConstraints constraints = new GridConstraints();
constraints.setFill(GridConstraints.FILL_BOTH);
form.myOptionsPanel.add(form.myOptionsForm.getMainPanel(), constraints);
form.myLabel.setText(configuration.getTestFrameworkName());
form.addCustomOptions(ObjectArrays.concat(customOptions, new CustomOption(PyUniversalTestsKt.getAdditionalArgumentsPropertyName(), TestTargetType.values())));
configuration.copyTo(ReflectionUtilsKt.getProperties(form, null, true));
return form;
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class CreateVirtualEnvDialog method layoutPanel.
protected void layoutPanel(final List<Sdk> allSdks) {
final GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(2, 2, 2, 2);
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.0;
myMainPanel.add(new JBLabel(PyBundle.message("sdk.create.venv.dialog.label.name")), c);
c.gridx = 1;
c.gridy = 0;
c.gridwidth = 2;
c.weightx = 1.0;
myMainPanel.add(myName, c);
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 1;
c.weightx = 0.0;
myMainPanel.add(new JBLabel(PyBundle.message("sdk.create.venv.dialog.label.location")), c);
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 2;
c.weightx = 1.0;
myMainPanel.add(myDestination, c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
c.weightx = 0.0;
myMainPanel.add(new JBLabel(PyBundle.message("sdk.create.venv.dialog.label.base.interpreter")), c);
c.gridx = 1;
c.gridy = 2;
mySdkCombo = new ComboBox();
c.insets = new Insets(2, 2, 2, 2);
c.weightx = 1.0;
myMainPanel.add(mySdkCombo, c);
c.gridx = 2;
c.gridy = 2;
c.insets = new Insets(0, 0, 2, 2);
c.weightx = 0.0;
FixedSizeButton button = new FixedSizeButton();
button.setPreferredSize(myDestination.getButton().getPreferredSize());
myMainPanel.add(button, c);
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 3;
c.insets = new Insets(2, 2, 2, 2);
mySitePackagesCheckBox = new JBCheckBox(PyBundle.message("sdk.create.venv.dialog.label.inherit.global.site.packages"));
myMainPanel.add(mySitePackagesCheckBox, c);
c.gridx = 0;
c.gridy = 4;
myMainPanel.add(myMakeAvailableToAllProjectsCheckbox, c);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final PythonSdkType sdkType = PythonSdkType.getInstance();
final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
String suggestedPath = sdkType.suggestHomePath();
VirtualFile suggestedDir = suggestedPath == null ? null : LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(suggestedPath));
final NullableConsumer<Sdk> consumer = sdk -> {
if (sdk == null)
return;
if (!allSdks.contains(sdk)) {
allSdks.add(sdk);
}
updateSdkList(allSdks, sdk);
};
FileChooser.chooseFiles(descriptor, myProject, suggestedDir, new FileChooser.FileChooserConsumer() {
@Override
public void consume(List<VirtualFile> selectedFiles) {
String path = selectedFiles.get(0).getPath();
if (sdkType.isValidSdkHome(path)) {
path = FileUtil.toSystemDependentName(path);
Sdk newSdk = null;
for (Sdk sdk : allSdks) {
if (path.equals(sdk.getHomePath())) {
newSdk = sdk;
}
}
if (newSdk == null) {
newSdk = new PyDetectedSdk(path);
}
consumer.consume(newSdk);
}
}
@Override
public void cancelled() {
}
});
}
});
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class SSHCredentialsDialog method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getSource() == myPasswordButton || e.getSource() == myKeyButton || e.getSource() == mySshAgentButton) {
updateFields();
checkKeyFile();
updateOKButton();
} else {
final String[] path = { myKeyFileText.getText() };
VirtualFile file;
if (path[0] != null && path[0].trim().length() > 0) {
path[0] = "file://" + path[0].replace(File.separatorChar, '/');
file = VirtualFileManager.getInstance().findFileByUrl(path[0]);
} else {
path[0] = "file://" + SystemProperties.getUserHome() + "/.ssh/identity";
path[0] = path[0].replace(File.separatorChar, '/');
file = VirtualFileManager.getInstance().findFileByUrl(path[0]);
if (file == null || !file.exists()) {
path[0] = "file://" + SystemProperties.getUserHome() + "/.ssh";
file = VirtualFileManager.getInstance().findFileByUrl(path[0]);
}
}
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withTitle(SvnBundle.message("dialog.title.openssh.v2.private.key")).withDescription(SvnBundle.message("dialog.description.openssh.v2.private.key")).withShowFileSystemRoots(true).withHideIgnored(false).withShowHiddenFiles(true);
FileChooser.chooseFiles(descriptor, myProject, file, files -> {
if (files.size() == 1) {
path[0] = FileUtil.toSystemDependentName(files.get(0).getPath());
myKeyFileText.setText(path[0]);
}
checkKeyFile();
updateOKButton();
});
}
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class ImportOptionsDialog method actionPerformed.
public void actionPerformed(ActionEvent e) {
// choose directory here/
FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor();
fcd.setShowFileSystemRoots(true);
fcd.setTitle("Checkout Directory");
fcd.setDescription("Select directory to checkout from subversion");
fcd.setHideIgnored(false);
VirtualFile file = FileChooser.chooseFile(fcd, getContentPane(), myProject, null);
if (file == null) {
return;
}
myPathField.setText(file.getPath().replace('/', File.separatorChar));
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class CaptureConfigurable method createComponent.
@Nullable
@Override
public JComponent createComponent() {
myTableModel = new MyTableModel();
JBTable table = new JBTable(myTableModel);
table.setColumnSelectionAllowed(false);
TableColumnModel columnModel = table.getColumnModel();
TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
myTableModel.addRow();
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.removeSelectedItems(table);
}
});
decorator.setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsUp(table);
}
});
decorator.setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsDown(table);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() == 1;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> {
try {
int idx = myTableModel.add(c.clone());
table.getSelectionModel().setSelectionInterval(idx, idx);
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
table.repaint();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
table.repaint();
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
table.repaint();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.getFileType() == StdFileTypes.XML;
}
};
descriptor.setDescription("Please select a file to import.");
descriptor.setTitle("Import Capture Points");
VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
if (ArrayUtil.isEmpty(files))
return;
table.getSelectionModel().clearSelection();
for (VirtualFile file : files) {
try {
Document document = JDOMUtil.loadDocument(file.getInputStream());
List<Element> children = document.getRootElement().getChildren();
children.forEach(element -> {
int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
table.getSelectionModel().addSelectionInterval(idx, idx);
});
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
if (wrapper == null)
return;
Element rootElement = new Element("capture-points");
selectedCapturePoints(table).forEach(c -> {
try {
CapturePoint clone = c.clone();
clone.myEnabled = false;
rootElement.addContent(XmlSerializer.serialize(clone));
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
try {
JDOMUtil.write(rootElement, wrapper.getFile());
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
});
BorderLayoutPanel panel = JBUI.Panels.simplePanel();
panel.addToCenter(decorator.createPanel());
myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
panel.addToBottom(myCaptureVariables);
return panel;
}
Aggregations