Search in sources :

Example 91 with FileChooserDescriptor

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePathAndPathInPackage(com.intellij.lang.javascript.flex.projectStructure.model.AirPackagingOptions.FilePathAndPathInPackage) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AnActionButton(com.intellij.ui.AnActionButton)

Example 92 with FileChooserDescriptor

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();
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) CellEditorComponentWithBrowseButton(com.intellij.util.ui.CellEditorComponentWithBrowseButton) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener)

Example 93 with FileChooserDescriptor

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerOptionInfo(com.intellij.flex.model.bc.CompilerOptionInfo) ExtensionAwareFileChooserDescriptor(com.intellij.lang.javascript.flex.projectStructure.ui.CompilerOptionsConfigurable.ExtensionAwareFileChooserDescriptor) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 94 with FileChooserDescriptor

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 95 with FileChooserDescriptor

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();
}
Also used : NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) FileDrop(com.intellij.openapi.fileChooser.ex.FileDrop) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PopupHandler(com.intellij.ui.PopupHandler) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)143 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 NotNull (org.jetbrains.annotations.NotNull)35 Project (com.intellij.openapi.project.Project)21 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)19 Nullable (org.jetbrains.annotations.Nullable)18 ActionEvent (java.awt.event.ActionEvent)17 File (java.io.File)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)13 DocumentAdapter (com.intellij.ui.DocumentAdapter)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 IOException (java.io.IOException)8 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 Module (com.intellij.openapi.module.Module)5 StringUtil (com.intellij.openapi.util.text.StringUtil)5 JBTable (com.intellij.ui.table.JBTable)5