use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-plugins by JetBrains.
the class FilesToPackageForm method initTableButtons.
private void initTableButtons() {
ToolbarDecorator d = ToolbarDecorator.createDecorator(myFilesToPackageTable);
d.setAddAction(new AnActionButtonRunnable() {
public void run(AnActionButton button) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, true, false, true);
final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myProject, null);
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
for (final VirtualFile file : files) {
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file);
String relativePath = sourceRoot == null ? null : sourceRoot.equals(file) ? "." : VfsUtilCore.getRelativePath(file, sourceRoot, '/');
myFilesToPackage.add(new FilePathAndPathInPackage(file.getPath(), StringUtil.notNullize(relativePath, file.getName())));
}
if (files.length > 0) {
fireDataChanged();
IdeFocusManager.getInstance(myProject).requestFocus(myFilesToPackageTable, true);
final int rowCount = myFilesToPackageTable.getRowCount();
myFilesToPackageTable.setRowSelectionInterval(rowCount - files.length, rowCount - 1);
}
}
});
d.setRemoveAction(new AnActionButtonRunnable() {
public void run(AnActionButton anActionButton) {
TableUtil.stopEditing(myFilesToPackageTable);
final int[] selectedRows = myFilesToPackageTable.getSelectedRows();
Arrays.sort(selectedRows);
for (int i = selectedRows.length - 1; i >= 0; i--) {
myFilesToPackage.remove(selectedRows[i]);
}
fireDataChanged();
}
});
myMainPanel.add(d.createPanel(), BorderLayout.CENTER);
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-plugins by JetBrains.
the class FilesToPackageForm method initTable.
private void initTable() {
myFilesToPackageTable = new JBTable();
// otherwise model is not in sync with view
myFilesToPackageTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
myFilesToPackageTable.setPreferredScrollableViewportSize(JBUI.size(400, 150));
myFilesToPackageTable.setRowHeight(new JTextField("Fake").getPreferredSize().height + myFilesToPackageTable.getRowMargin());
myFilesToPackageTable.setModel(new DefaultTableModel() {
public int getColumnCount() {
return Column.values().length;
}
public int getRowCount() {
return myFilesToPackage.size();
}
public String getColumnName(int column) {
return Column.values()[column].getColumnName();
}
public Class<?> getColumnClass(int column) {
return Column.values()[column].getColumnClass();
}
public Object getValueAt(int row, int column) {
return Column.values()[column].getValue(myFilesToPackage.get(row));
}
public void setValueAt(Object aValue, int row, int column) {
Column.values()[column].setValue(myFilesToPackage, row, aValue);
}
});
myFilesToPackageTable.getColumnModel().getColumn(0).setCellEditor(new AbstractTableCellEditor() {
private CellEditorComponentWithBrowseButton<JTextField> myComponent;
public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, int row, int column) {
final ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor d = new FileChooserDescriptor(true, true, false, true, false, false);
VirtualFile initialFile = LocalFileSystem.getInstance().findFileByPath((String) getCellEditorValue());
VirtualFile file = FileChooser.chooseFile(d, myProject, initialFile);
if (file != null) {
myComponent.getChildComponent().setText(file.getPresentableUrl());
}
}
};
myComponent = new CellEditorComponentWithBrowseButton<>(new TextFieldWithBrowseButton(listener), this);
myComponent.getChildComponent().setText((String) value);
return myComponent;
}
public Object getCellEditorValue() {
return myComponent.getChildComponent().getText();
}
});
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-plugins by JetBrains.
the class RepeatableValueDialog method addObject.
protected boolean addObject() {
final CompilerOptionInfo.ListElement firstElement = myInfo.LIST_ELEMENTS[0];
if (myInfo.LIST_ELEMENTS.length == 1 && (firstElement.LIST_ELEMENT_TYPE == ListElementType.File || firstElement.LIST_ELEMENT_TYPE == ListElementType.FileOrFolder)) {
final FileChooserDescriptor descriptor = firstElement.LIST_ELEMENT_TYPE == ListElementType.File ? FlexUtils.createFileChooserDescriptor(firstElement.FILE_EXTENSIONS) : FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
if (file != null) {
getCurrentList().add(new StringBuilder(file.getPath()));
return true;
}
} else {
final StringBuilder b = new StringBuilder();
boolean first = true;
for (CompilerOptionInfo.ListElement listElement : myInfo.LIST_ELEMENTS) {
if (first) {
first = false;
} else {
b.append(CompilerOptionInfo.LIST_ENTRY_PARTS_SEPARATOR);
}
b.append(listElement.DEFAULT_VALUE);
}
getCurrentList().add(b);
return true;
}
return false;
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class VcsProjectSetProcessor method getDirectory.
private static boolean getDirectory(@NotNull Context context) {
if (context.directory != null)
return true;
FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false);
descriptor.setTitle("Select Destination Folder");
descriptor.setDescription("");
VirtualFile[] files = FileChooser.chooseFiles(descriptor, null, null);
context.directory = files.length == 0 ? null : files[0];
return context.directory != null;
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class SelectLocationStep method init.
protected void init() {
final DefaultActionGroup fileSystemActionGroup = createFileSystemActionGroup();
myFileSystemToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, fileSystemActionGroup, true);
final JTree tree = myFileSystemTree.getTree();
tree.getSelectionModel().addTreeSelectionListener(myTreeSelectionListener);
tree.setCellRenderer(new NodeRenderer());
tree.addMouseListener(new PopupHandler() {
public void invokePopup(Component comp, int x, int y) {
final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UPDATE_POPUP, fileSystemActionGroup);
popupMenu.getComponent().show(comp, x, y);
}
});
tree.addSelectionPath(tree.getPathForRow(0));
new FileDrop(tree, new FileDrop.Target() {
public FileChooserDescriptor getDescriptor() {
return myChooserDescriptor;
}
public boolean isHiddenShown() {
return myFileSystemTree.areHiddensShown();
}
public void dropFiles(final List<VirtualFile> files) {
if (files.size() > 0) {
selectInTree(files.toArray(new VirtualFile[files.size()]));
}
}
});
super.init();
}
Aggregations