List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createAllButJarContentsDescriptor
public static FileChooserDescriptor createAllButJarContentsDescriptor()
From source file:com.intellij.compiler.options.ProcessorProfilePanel.java
License:Apache License
public ProcessorProfilePanel(Project project) { super(new GridBagLayout()); myProject = project;/* ww w. j a v a 2 s.c o m*/ myCbEnableProcessing = new JCheckBox("Enable annotation processing"); { myRbClasspath = new JRadioButton("Obtain processors from project classpath"); myRbProcessorsPath = new JRadioButton("Processor path:"); ButtonGroup group = new ButtonGroup(); group.add(myRbClasspath); group.add(myRbProcessorsPath); } { myRbRelativeToContentRoot = new JRadioButton("Module content root"); myRbRelativeToOutputRoot = new JRadioButton("Module output directory"); final ButtonGroup group = new ButtonGroup(); group.add(myRbRelativeToContentRoot); group.add(myRbRelativeToOutputRoot); } myProcessorPathField = new TextFieldWithBrowseButton(new ActionListener() { public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createAllButJarContentsDescriptor(); final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myProcessorPathField, myProject, null); if (files.length > 0) { final StringBuilder builder = new StringBuilder(); for (VirtualFile file : files) { if (builder.length() > 0) { builder.append(File.pathSeparator); } builder.append(FileUtil.toSystemDependentName(file.getPath())); } myProcessorPathField.setText(builder.toString()); } } }); myProcessorTablePanel = new JPanel(new BorderLayout()); myProcessorsModel = new ProcessorTableModel(); myProcessorTablePanel.setBorder(IdeBorderFactory.createTitledBorder("Annotation Processors", false)); myProcessorTable = new JBTable(myProcessorsModel); myProcessorTable.getEmptyText().setText("Compiler will run all automatically discovered processors"); myProcessorPanel = createTablePanel(myProcessorTable); myProcessorTablePanel.add(myProcessorPanel, BorderLayout.CENTER); myOptionsTablePanel = new JPanel(new BorderLayout()); myOptionsModel = new OptionsTableModel(); myOptionsTablePanel.setBorder(IdeBorderFactory.createTitledBorder("Annotation Processor options", false)); myOptionsTable = new JBTable(myOptionsModel); myOptionsTable.getEmptyText().setText("No processor-specific options configured"); myOptionsPanel = createTablePanel(myOptionsTable); myOptionsTablePanel.add(myOptionsPanel, BorderLayout.CENTER); myGeneratedProductionDirField = new JTextField(); myGeneratedTestsDirField = new JTextField(); myWarninglabel = new JLabel("<html>WARNING!<br>" + /*"All source files located in the generated sources output directory WILL BE EXCLUDED from annotation processing. " +*/ "If option 'Clear output directory on rebuild' is enabled, " + "the entire contents of directories where generated sources are stored WILL BE CLEARED on rebuild.</html>"); myWarninglabel.setFont(myWarninglabel.getFont().deriveFont(Font.BOLD)); add(myCbEnableProcessing, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); add(myRbClasspath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0)); add(myRbProcessorsPath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0)); add(myProcessorPathField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); myStoreGenSourcesLabel = new JLabel("Store generated sources relative to: "); add(myStoreGenSourcesLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 0, 0), 0, 0)); add(myRbRelativeToOutputRoot, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 0, 0), 0, 0)); add(myRbRelativeToContentRoot, new GridBagConstraints(2, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 0, 0), 0, 0)); myProductionLabel = new JLabel("Production sources directory:"); add(myProductionLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); add(myGeneratedProductionDirField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); myTestLabel = new JLabel("Test sources directory:"); add(myTestLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); add(myGeneratedTestsDirField, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); add(myProcessorTablePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); add(myOptionsTablePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0)); add(myWarninglabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0)); myRbClasspath.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { updateEnabledState(); } }); myProcessorTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateEnabledState(); } } }); myCbEnableProcessing.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { updateEnabledState(); } }); updateEnabledState(); }
From source file:com.intellij.vcs.log.ui.VcsStructureChooser.java
License:Apache License
@Override protected JComponent createCenterPanel() { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createAllButJarContentsDescriptor(); calculateRoots();/*from ww w . ja v a 2 s . co m*/ final ArrayList<VirtualFile> list = new ArrayList<VirtualFile>(myRoots); final Comparator<VirtualFile> comparator = new Comparator<VirtualFile>() { @Override public int compare(VirtualFile o1, VirtualFile o2) { final boolean isDir1 = o1.isDirectory(); final boolean isDir2 = o2.isDirectory(); if (isDir1 != isDir2) return isDir1 ? -1 : 1; final String module1 = myModulesSet.get(o1); final String path1 = module1 != null ? module1 : o1.getPath(); final String module2 = myModulesSet.get(o2); final String path2 = module2 != null ? module2 : o2.getPath(); return path1.compareToIgnoreCase(path2); } }; descriptor.setRoots(list); myTree = new Tree(); myTree.setMinimumSize(new Dimension(200, 200)); myTree.setBorder(BORDER); myTree.setShowsRootHandles(true); myTree.setRootVisible(true); myTree.getExpandableItemsHandler().setEnabled(false); final MyCheckboxTreeCellRenderer cellRenderer = new MyCheckboxTreeCellRenderer(mySelectionManager, myModulesSet, myProject, myTree, myRoots); final FileSystemTreeImpl fileSystemTree = new FileSystemTreeImpl(myProject, descriptor, myTree, cellRenderer, null, new Convertor<TreePath, String>() { @Override public String convert(TreePath o) { final DefaultMutableTreeNode lastPathComponent = ((DefaultMutableTreeNode) o .getLastPathComponent()); final Object uo = lastPathComponent.getUserObject(); if (uo instanceof FileNodeDescriptor) { final VirtualFile file = ((FileNodeDescriptor) uo).getElement().getFile(); final String module = myModulesSet.get(file); if (module != null) return module; return file == null ? "" : file.getName(); } return o.toString(); } }); final AbstractTreeUi ui = fileSystemTree.getTreeBuilder().getUi(); ui.setNodeDescriptorComparator(new Comparator<NodeDescriptor>() { @Override public int compare(NodeDescriptor o1, NodeDescriptor o2) { if (o1 instanceof FileNodeDescriptor && o2 instanceof FileNodeDescriptor) { final VirtualFile f1 = ((FileNodeDescriptor) o1).getElement().getFile(); final VirtualFile f2 = ((FileNodeDescriptor) o2).getElement().getFile(); return comparator.compare(f1, f2); } return o1.getIndex() - o2.getIndex(); } }); myRoot = (DefaultMutableTreeNode) myTree.getModel().getRoot(); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { int row = myTree.getRowForLocation(e.getX(), e.getY()); if (row < 0) return false; final Object o = myTree.getPathForRow(row).getLastPathComponent(); if (myRoot == o || getFile(o) == null) return false; Rectangle rowBounds = myTree.getRowBounds(row); cellRenderer.setBounds(rowBounds); Rectangle checkBounds = cellRenderer.myCheckbox.getBounds(); checkBounds.setLocation(rowBounds.getLocation()); if (checkBounds.height == 0) checkBounds.height = rowBounds.height; if (checkBounds.contains(e.getPoint())) { mySelectionManager.toggleSelection((DefaultMutableTreeNode) o); myTree.revalidate(); myTree.repaint(); } return true; } }.installOn(myTree); myTree.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) return; for (TreePath path : paths) { if (path == null) continue; final Object o = path.getLastPathComponent(); if (myRoot == o || getFile(o) == null) return; mySelectionManager.toggleSelection((DefaultMutableTreeNode) o); } myTree.revalidate(); myTree.repaint(); e.consume(); } } }); JBPanel panel = new JBPanel(new BorderLayout()); panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER); mySelectedLabel = new JLabel(""); mySelectedLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0)); panel.add(mySelectedLabel, BorderLayout.SOUTH); mySelectionManager.setSelectionChangeListener(new PlusMinus<VirtualFile>() { @Override public void plus(VirtualFile virtualFile) { mySelectedFiles.add(virtualFile); recalculateErrorText(); } private void recalculateErrorText() { checkEmpty(); if (mySelectionManager.canAddSelection()) { mySelectedLabel.setText(""); } else { mySelectedLabel.setText(CAN_NOT_ADD_TEXT); } mySelectedLabel.revalidate(); } @Override public void minus(VirtualFile virtualFile) { mySelectedFiles.remove(virtualFile); recalculateErrorText(); } }); return panel; }
From source file:com.sylvanaar.idea.Lua.library.LuaLibraryType.java
License:Apache License
@Override public NewLibraryConfiguration createNewLibrary(@NotNull JComponent jComponent, @Nullable VirtualFile virtualFile, @NotNull Project project) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createAllButJarContentsDescriptor(); descriptor.setTitle(LuaBundle.message("new.library.file.chooser.title")); descriptor.setDescription(LuaBundle.message("new.library.file.chooser.description")); final VirtualFile[] files = FileChooser.chooseFiles(descriptor, project, virtualFile); if (files.length == 0) { return null; }/*from w w w .ja v a 2 s . c o m*/ return new NewLibraryConfiguration("Lua Library", this, new LuaLibraryProperties()) { @Override public void addRoots(@NotNull LibraryEditor editor) { for (VirtualFile file : files) { editor.addRoot(file, OrderRootType.CLASSES); } } }; }