/** Init components */ private void initListeners() { FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor(); fcd.setShowFileSystemRoots(true); fcd.setTitle(GitBundle.getString("clone.destination.directory.title")); fcd.setDescription(GitBundle.getString("clone.destination.directory.description")); fcd.setHideIgnored(false); myParentDirectory.addActionListener( new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( fcd.getTitle(), fcd.getDescription(), myParentDirectory, myProject, fcd, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) { @Override protected VirtualFile getInitialFile() { // suggest project base directory only if nothing is typed in the component. String text = getComponentText(); if (text.length() == 0) { VirtualFile file = myProject.getBaseDir(); if (file != null) { return file; } } return super.getInitialFile(); } }); final DocumentListener updateOkButtonListener = new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { updateButtons(); } }; myParentDirectory.getChildComponent().getDocument().addDocumentListener(updateOkButtonListener); String parentDir = GitRememberedInputs.getInstance().getCloneParentDir(); if (StringUtil.isEmptyOrSpaces(parentDir)) { parentDir = ProjectUtil.getBaseDir(); } myParentDirectory.setText(parentDir); myDirectoryName.getDocument().addDocumentListener(updateOkButtonListener); myTestButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { test(); } }); setOKActionEnabled(false); myTestButton.setEnabled(false); }
public static void setupMainClassField( final Project project, final TextFieldWithBrowseButton field) { field.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final PsiClass selected = selectMainClass(project, field.getText()); if (selected != null) { field.setText(selected.getQualifiedName()); } } }); }
public ElementWithManifestPropertiesPanel(E element, final ArtifactEditorContext context) { myElement = element; myContext = context; ManifestFileUtil.setupMainClassField(context.getProject(), myMainClassField); myClasspathField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Messages.showTextAreaDialog( myClasspathField.getTextField(), "Edit Classpath", "classpath-attribute-editor"); } }); myClasspathField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { myContext.queueValidation(); } }); myUseExistingManifestButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { chooseManifest(); } }); myCreateManifestButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { createManifest(); } }); }
public DirDiffPanel(DirDiffTableModel model, DirDiffWindow wnd) { myModel = model; myDiffWindow = wnd; mySourceDirField.setText(model.getSourceDir().getPath()); myTargetDirField.setText(model.getTargetDir().getPath()); mySourceDirField.setBorder(JBUI.Borders.emptyRight(8)); myTargetDirField.setBorder(JBUI.Borders.emptyRight(12)); mySourceDirLabel.setIcon(model.getSourceDir().getIcon()); myTargetDirLabel.setIcon(model.getTargetDir().getIcon()); myTargetDirLabel.setBorder(JBUI.Borders.emptyLeft(8)); myModel.setTable(myTable); myModel.setPanel(this); Disposer.register(this, myModel); myTable.setModel(myModel); new TableSpeedSearch(myTable); final DirDiffTableCellRenderer renderer = new DirDiffTableCellRenderer(); myTable.setExpandableItemsEnabled(false); myTable.setDefaultRenderer(Object.class, renderer); myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final Project project = myModel.getProject(); myTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { final int lastIndex = e.getLastIndex(); final int firstIndex = e.getFirstIndex(); final DirDiffElementImpl last = myModel.getElementAt(lastIndex); final DirDiffElementImpl first = myModel.getElementAt(firstIndex); if (last == null || first == null) { update(false); return; } if (last.isSeparator()) { final int ind = lastIndex + ((lastIndex < firstIndex) ? 1 : -1); myTable.getSelectionModel().addSelectionInterval(ind, ind); } else if (first.isSeparator()) { final int ind = firstIndex + ((firstIndex < lastIndex) ? 1 : -1); myTable.getSelectionModel().addSelectionInterval(ind, ind); } else { update(false); } myDiffWindow.setTitle(myModel.getTitle()); } }); if (model.isOperationsEnabled()) { new AnAction("Change diff operation") { @Override public void actionPerformed(AnActionEvent e) { changeOperationForSelection(); } }.registerCustomShortcutSet(CustomShortcutSet.fromString("SPACE"), myTable); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { if (e.getButton() == MouseEvent.BUTTON3) return false; if (myTable.getRowCount() > 0) { final int row = myTable.rowAtPoint(e.getPoint()); final int col = myTable.columnAtPoint(e.getPoint()); if (row != -1 && col == ((myTable.getColumnCount() - 1) / 2)) { changeOperationForSelection(); } } return true; } }.installOn(myTable); } myTable.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { final int keyCode = e.getKeyCode(); int row; if (keyCode == KeyEvent.VK_DOWN) { row = getNextRow(); } else if (keyCode == KeyEvent.VK_UP) { row = getPrevRow(); } else { row = -1; } if (row != -1) { selectRow(row, e.isShiftDown()); e.consume(); } } }); final TableColumnModel columnModel = myTable.getColumnModel(); final TableColumn operationColumn = columnModel.getColumn((columnModel.getColumnCount() - 1) / 2); operationColumn.setMaxWidth(JBUI.scale(25)); operationColumn.setMinWidth(JBUI.scale(25)); for (int i = 0; i < columnModel.getColumnCount(); i++) { final String name = myModel.getColumnName(i); final TableColumn column = columnModel.getColumn(i); if (DirDiffTableModel.COLUMN_DATE.equals(name)) { column.setMaxWidth(JBUI.scale(90)); column.setMinWidth(JBUI.scale(90)); } else if (DirDiffTableModel.COLUMN_SIZE.equals(name)) { column.setMaxWidth(JBUI.scale(120)); column.setMinWidth(JBUI.scale(120)); } } final DirDiffToolbarActions actions = new DirDiffToolbarActions(myModel, myDiffPanel); final ActionManager actionManager = ActionManager.getInstance(); final ActionToolbar toolbar = actionManager.createActionToolbar("DirDiff", actions, true); registerCustomShortcuts(actions, myTable); myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER); final JBLabel label = new JBLabel( "Use Space button or mouse click to change operation for the selected elements." + " Enter to perform.", SwingConstants.CENTER); label.setForeground(UIUtil.getInactiveTextColor()); UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label); DataManager.registerDataProvider(myFilesPanel, this); myTable.addMouseListener( new PopupHandler() { @Override public void invokePopup(Component comp, int x, int y) { final JPopupMenu popupMenu = actionManager .createActionPopupMenu( "DirDiffPanel", (ActionGroup) actionManager.getAction("DirDiffMenu")) .getComponent(); popupMenu.show(comp, x, y); } }); myFilesPanel.add(label, BorderLayout.SOUTH); final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable()); loadingPanel.addListener( new JBLoadingPanelListener.Adapter() { boolean showHelp = true; @Override public void onLoadingFinish() { if (showHelp && myModel.isOperationsEnabled() && myModel.getRowCount() > 0) { final long count = PropertiesComponent.getInstance().getOrInitLong("dir.diff.space.button.info", 0); if (count < 3) { JBPopupFactory.getInstance() .createBalloonBuilder(new JLabel(" Use Space button to change operation")) .setFadeoutTime(5000) .setContentInsets(JBUI.insets(15)) .createBalloon() .show( new RelativePoint(myTable, new Point(myTable.getWidth() / 2, 0)), Balloon.Position.above); PropertiesComponent.getInstance() .setValue("dir.diff.space.button.info", String.valueOf(count + 1)); } } showHelp = false; } }); loadingPanel.add(myComponent, BorderLayout.CENTER); myTable.putClientProperty(myModel.DECORATOR, loadingPanel); myTable.addComponentListener( new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { myTable.removeComponentListener(this); myModel.reloadModel(false); } }); myRootPanel.removeAll(); myRootPanel.add(loadingPanel, BorderLayout.CENTER); myFilter = new FilterComponent("dir.diff.filter", 15, false) { @Override public void filter() { fireFilterUpdated(); } @Override protected void onEscape(KeyEvent e) { e.consume(); focusTable(); } @Override protected JComponent getPopupLocationComponent() { return UIUtil.findComponentOfType( super.getPopupLocationComponent(), JTextComponent.class); } }; myModel.addModelListener( new DirDiffModelListener() { @Override public void updateStarted() { myFilter.setEnabled(false); } @Override public void updateFinished() { myFilter.setEnabled(true); } }); myFilter.getTextEditor().setColumns(10); myFilter.setFilter(myModel.getSettings().getFilter()); // oldFilter = myFilter.getText(); oldFilter = myFilter.getFilter(); myFilterPanel.add(myFilter, BorderLayout.CENTER); myFilterLabel.setLabelFor(myFilter); final Callable<DiffElement> srcChooser = myModel.getSourceDir().getElementChooser(project); final Callable<DiffElement> trgChooser = myModel.getTargetDir().getElementChooser(project); mySourceDirField.setEditable(false); myTargetDirField.setEditable(false); if (srcChooser != null && myModel.getSettings().enableChoosers) { mySourceDirField.setButtonEnabled(true); mySourceDirField.addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { final Callable<DiffElement> chooser = myModel.getSourceDir().getElementChooser(project); if (chooser == null) return; final DiffElement newElement = chooser.call(); if (newElement != null) { if (!StringUtil.equals(mySourceDirField.getText(), newElement.getPath())) { myModel.setSourceDir(newElement); mySourceDirField.setText(newElement.getPath()); String shortcutsText = KeymapUtil.getShortcutsText( RefreshDirDiffAction.REFRESH_SHORTCUT.getShortcuts()); myModel.clearWithMessage( "Source or Target has been changed." + " Please run Refresh (" + shortcutsText + ")"); } } } catch (Exception ignored) { } } }); } else { Dimension preferredSize = mySourceDirField.getPreferredSize(); mySourceDirField.setButtonEnabled(false); mySourceDirField.getButton().setVisible(false); mySourceDirField.setPreferredSize(preferredSize); } if (trgChooser != null && myModel.getSettings().enableChoosers) { myTargetDirField.setButtonEnabled(true); myTargetDirField.addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { final Callable<DiffElement> chooser = myModel.getTargetDir().getElementChooser(project); if (chooser == null) return; final DiffElement newElement = chooser.call(); if (newElement != null) { myModel.setTargetDir(newElement); myTargetDirField.setText(newElement.getPath()); } } catch (Exception ignored) { } } }); } else { Dimension preferredSize = myTargetDirField.getPreferredSize(); myTargetDirField.setButtonEnabled(false); myTargetDirField.getButton().setVisible(false); myTargetDirField.setPreferredSize(preferredSize); } myDiffRequestProcessor = new MyDiffRequestProcessor(project); Disposer.register(this, myDiffRequestProcessor); myDiffPanel.add(myDiffRequestProcessor.getComponent(), BorderLayout.CENTER); myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable(); }
@NotNull @Override protected JComponent createComponent(@NotNull CreationContext creationContext) { JPanel panel = new JPanel(new GridBagLayout()); { GridBagConstraints c = new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(UIUtil.DEFAULT_VGAP, 0, 0, UIUtil.DEFAULT_HGAP), 0, 0); myLabel.setDisplayedMnemonic('C'); myLabel.setHorizontalAlignment(SwingConstants.RIGHT); myLabel.setLabelFor(myConfigFileTextFieldWithBrowseButton.getTextField()); panel.add(myLabel, c); } { GridBagConstraints c = new GridBagConstraints( 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(UIUtil.DEFAULT_VGAP, 0, 0, 0), 0, 0); final Project project = creationContext.getProject(); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { boolean visible = super.isFileVisible(file, showHiddenFiles); if (visible && !file.isDirectory() && !showHiddenFiles) { visible = JstdConfigFileUtils.isJstdConfigFile(file); } return visible; } }; final JTextField configFileTextField = myConfigFileTextFieldWithBrowseButton.getTextField(); FileChooserFactory.getInstance() .installFileCompletion(configFileTextField, descriptor, false, null); myConfigFileTextFieldWithBrowseButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PsiFile initialPsiFile = getConfigFile(project); TreeFileChooserDialog fileChooser = new TreeFileChooserDialog( project, "Select JsTestDriver configuration file", initialPsiFile, JstdConfigFileType.INSTANCE, new TreeFileChooser.PsiFileFilter() { @Override public boolean accept(PsiFile psiFile) { return true; } }, false, false); boolean jstdConfigFilesExists = JstdSettingsUtil.areJstdConfigFilesInProject(project); if (jstdConfigFilesExists) { fileChooser.selectSearchByNameTab(); } fileChooser.showDialog(); PsiFile psiFile = fileChooser.getSelectedFile(); if (psiFile != null) { VirtualFile vFile = psiFile.getVirtualFile(); if (vFile != null) { String path = FileUtil.toSystemDependentName(vFile.getPath()); configFileTextField.setText(path); } } } }); panel.add(myConfigFileTextFieldWithBrowseButton, c); } SwingUtils.addGreedyBottomRow(panel); return panel; }
/** Init components */ private void initListeners() { FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false); fcd.setShowFileSystemRoots(true); fcd.setTitle(GitBundle.getString("clone.destination.directory.title")); fcd.setDescription(GitBundle.getString("clone.destination.directory.description")); fcd.setHideIgnored(false); myParentDirectory.addActionListener( new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( fcd.getTitle(), fcd.getDescription(), myParentDirectory, myProject, fcd, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) { @Override protected VirtualFile getInitialFile() { // suggest project base directory only if nothing is typed in the component. String text = getComponentText(); if (text.length() == 0) { VirtualFile file = myProject.getBaseDir(); if (file != null) { return file; } } return super.getInitialFile(); } }); final DocumentListener updateOkButtonListener = new DocumentListener() { // update Ok button state depending on the current state of the fields public void insertUpdate(final DocumentEvent e) { updateOkButton(); } public void removeUpdate(final DocumentEvent e) { updateOkButton(); } public void changedUpdate(final DocumentEvent e) { updateOkButton(); } }; myParentDirectory.getChildComponent().getDocument().addDocumentListener(updateOkButtonListener); myDirectoryName.getDocument().addDocumentListener(updateOkButtonListener); myOriginName.getDocument().addDocumentListener(updateOkButtonListener); myRepositoryURL .getDocument() .addDocumentListener( new DocumentListener() { // enable test button only if something is entered in repository URL public void insertUpdate(final DocumentEvent e) { changed(); } public void removeUpdate(final DocumentEvent e) { changed(); } public void changedUpdate(final DocumentEvent e) { changed(); } private void changed() { final String url = myRepositoryURL.getText(); myTestButton.setEnabled(url.length() != 0); if (myDefaultDirectoryName.equals(myDirectoryName.getText()) || myDirectoryName.getText().length() == 0) { // modify field if it was unmodified or blank myDefaultDirectoryName = defaultDirectoryName(url); myDirectoryName.setText(myDefaultDirectoryName); } updateOkButton(); } }); myTestButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { myTestURL = myRepositoryURL.getText(); String output = GitHandlerUtil.doSynchronously( GitSimpleHandler.checkRepository(myProject, myTestURL), GitBundle.message("clone.testing", myTestURL), "connection test"); if (output != null) { Messages.showInfoMessage( myTestButton, GitBundle.message("clone.test.success.message", myTestURL), GitBundle.getString("clone.test.success")); myTestResult = Boolean.TRUE; } else { myTestResult = Boolean.FALSE; } updateOkButton(); } }); setOKActionEnabled(false); }
public LocationNameFieldsBinding( Project project, final TextFieldWithBrowseButton locationTextField, final JTextField nameTextField, String baseDir, final String browseFolderTitle) { myBaseDir = baseDir; File suggestedProjectDirectory = FileUtil.findSequentNonexistentFile(new File(baseDir), "untitled", ""); locationTextField.setText(suggestedProjectDirectory.toString()); nameTextField.setDocument(new NameFieldDocument(nameTextField, locationTextField)); mySuggestedProjectName = suggestedProjectDirectory.getName(); nameTextField.setText(mySuggestedProjectName); nameTextField.selectAll(); FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> listener = new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>( browseFolderTitle, "", locationTextField, project, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) { protected void onFileChoosen(VirtualFile chosenFile) { myBaseDir = chosenFile.getPath(); if (isProjectNameChanged(nameTextField.getText()) && !nameTextField.getText().equals(chosenFile.getName())) { myExternalModify = true; locationTextField.setText( new File(chosenFile.getPath(), nameTextField.getText()).toString()); myExternalModify = false; } else { myExternalModify = true; locationTextField.setText(chosenFile.getPath()); nameTextField.setText(chosenFile.getName()); myExternalModify = false; } } }; locationTextField.addActionListener(listener); locationTextField .getTextField() .getDocument() .addDocumentListener( new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { if (myExternalModify) { return; } myModifyingLocation = true; String path = locationTextField.getText().trim(); if (path.endsWith(File.separator)) { path = path.substring(0, path.length() - File.separator.length()); } int ind = path.lastIndexOf(File.separator); if (ind != -1) { String projectName = path.substring(ind + 1, path.length()); if (!nameTextField.getText().trim().isEmpty()) { myBaseDir = path.substring(0, ind); } if (!projectName.equals(nameTextField.getText())) { if (!myModifyingProjectName) { nameTextField.setText(projectName); } } } myModifyingLocation = false; } }); }