protected boolean askReloadFromDisk(final VirtualFile file, final Document document) { ApplicationManager.getApplication().assertIsDispatchThread(); if (!isDocumentUnsaved(document)) return true; String message = UIBundle.message("file.cache.conflict.message.text", file.getPresentableUrl()); if (ApplicationManager.getApplication().isUnitTestMode()) throw new RuntimeException(message); final DialogBuilder builder = new DialogBuilder((Project) null); builder.setCenterPanel(new JLabel(message, Messages.getQuestionIcon(), SwingConstants.CENTER)); builder.addOkAction().setText(UIBundle.message("file.cache.conflict.load.fs.changes.button")); builder .addCancelAction() .setText(UIBundle.message("file.cache.conflict.keep.memory.changes.button")); builder.addAction( new AbstractAction(UIBundle.message("file.cache.conflict.show.difference.button")) { @Override public void actionPerformed(ActionEvent e) { String title = UIBundle.message( "file.cache.conflict.for.file.dialog.title", file.getPresentableUrl()); final ProjectEx project = (ProjectEx) ProjectLocator.getInstance().guessProjectForFile(file); SimpleDiffRequest request = new SimpleDiffRequest(project, title); FileType fileType = file.getFileType(); String fsContent = LoadTextUtil.loadText(file).toString(); request.setContents( new SimpleContent(fsContent, fileType), new DocumentContent(project, document, fileType)); request.setContentTitles( UIBundle.message("file.cache.conflict.diff.content.file.system.content"), UIBundle.message("file.cache.conflict.diff.content.memory.content")); DialogBuilder diffBuilder = new DialogBuilder(project); DiffPanelImpl diffPanel = (DiffPanelImpl) DiffManager.getInstance() .createDiffPanel(diffBuilder.getWindow(), project, diffBuilder, null); diffPanel.getOptions().setShowSourcePolicy(DiffPanelOptions.ShowSourcePolicy.DONT_SHOW); diffBuilder.setCenterPanel(diffPanel.getComponent()); diffBuilder.setDimensionServiceKey("FileDocumentManager.FileCacheConflict"); diffPanel.setDiffRequest(request); diffBuilder .addOkAction() .setText(UIBundle.message("file.cache.conflict.save.changes.button")); diffBuilder.addCancelAction(); diffBuilder.setTitle(title); if (diffBuilder.show() == DialogWrapper.OK_EXIT_CODE) { builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE); } } }); builder.setTitle(UIBundle.message("file.cache.conflict.dialog.title")); builder.setButtonsAlignment(SwingConstants.CENTER); builder.setHelpId("reference.dialogs.fileCacheConflict"); return builder.show() == 0; }
private static DialogBuilder createChangeInfoDialog( Project project, @NotNull CCNewProjectPanel panel) { DialogBuilder builder = new DialogBuilder(project); builder.setTitle(ACTION_TEXT); JPanel changeInfoPanel = panel.getMainPanel(); changeInfoPanel.setMinimumSize(JBUI.size(400, 300)); builder.setCenterPanel(changeInfoPanel); return builder; }
public static void showPathsInDialog( @NotNull Project project, @NotNull Collection<String> absolutePaths, @NotNull String title, @Nullable String description) { DialogBuilder builder = new DialogBuilder(project); builder.setCenterPanel(new GitSimplePathsBrowser(project, absolutePaths)); if (description != null) { builder.setNorthPanel(new MultiLineLabel(description)); } builder.addOkAction(); builder.setTitle(title); builder.show(); }
public ImportFileDialog(final String defaultValue, final DialogBuilder dialogBuilder) { setLayout(new GridBagLayout()); _importDir = defaultValue; final GridBagConstraints c = new GridBagConstraints(); c.gridy = 1; c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.NORTHWEST; _dialogBuilder = dialogBuilder; final Component label = new JLabel("Import BugCollection from: "); c.weightx = 0; c.gridwidth = 2; add(label, c); _importFile = new JTextField(""); _importFile.setEditable(false); _importFile.setPreferredSize(new Dimension(200, 20)); c.weightx = 1; c.gridwidth = 1; add(_importFile, c); final AbstractButton browseButton = new JButton("Browse"); browseButton.addActionListener(new MyFileChooserActionListener()); c.weightx = 0; add(browseButton, c); c.gridx = GridBagConstraints.RELATIVE; c.gridy = 2; c.gridheight = 2; dialogBuilder.setCenterPanel(this); _importFile.getDocument().addDocumentListener(new MyDocumentAdapter()); if (!_importFile.getText().isEmpty()) { _selectedFile = new File(_importFile.getText()); } _importFile.addHierarchyListener( new HierarchyListener() { public void hierarchyChanged(final HierarchyEvent e) { if (_importFile.isVisible()) { _dialogBuilder.setOkActionEnabled(validateFile(_importFile.getDocument())); } } }); _dialogBuilder.setOkActionEnabled(_selectedFile != null && _selectedFile.isDirectory()); }
private void showDirDiffDialog( @NotNull FilePath path, @Nullable String hash1, @Nullable String hash2, @NotNull List<Change> diff) { DialogBuilder dialogBuilder = new DialogBuilder(myProject); String title; if (hash2 != null) { if (hash1 != null) { title = String.format( "Difference between %s and %s in %s", GitUtil.getShortHash(hash1), GitUtil.getShortHash(hash2), path.getName()); } else { title = String.format("Initial commit %s in %s", GitUtil.getShortHash(hash2), path.getName()); } } else { LOG.assertTrue(hash1 != null, "hash1 and hash2 can't both be null. Path: " + path); title = String.format( "Difference between %s and local version in %s", GitUtil.getShortHash(hash1), path.getName()); } dialogBuilder.setTitle(title); dialogBuilder.setActionDescriptors( new DialogBuilder.ActionDescriptor[] {new DialogBuilder.CloseDialogAction()}); final ChangesBrowser changesBrowser = new ChangesBrowser( myProject, null, diff, null, false, true, null, ChangesBrowser.MyUseCase.COMMITTED_CHANGES, null); changesBrowser.setChangesToDisplay(diff); dialogBuilder.setCenterPanel(changesBrowser); dialogBuilder.show(); }
public void show(DiffRequest request) { Collection hints = request.getHints(); boolean shouldOpenDialog = shouldOpenDialog(hints); if (shouldOpenDialog) { final DialogBuilder builder = new DialogBuilder(request.getProject()); DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true); if (diffPanel == null) { Disposer.dispose(builder); return; } if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) { diffPanel.setPatchAppliedApproximately(); // todo read only and not variants } final Runnable onOkRunnable = request.getOnOkRunnable(); if (onOkRunnable != null) { builder.setOkOperation( new Runnable() { @Override public void run() { builder.getDialogWrapper().close(0); onOkRunnable.run(); } }); } else { builder.removeAllActions(); } builder.setCenterPanel(diffPanel.getComponent()); builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent()); builder.setTitle(request.getWindowTitle()); builder.setDimensionServiceKey(request.getGroupKey()); new AnAction() { public void actionPerformed(final AnActionEvent e) { builder.getDialogWrapper().close(0); } }.registerCustomShortcutSet( new CustomShortcutSet( KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent()); showDiffDialog(builder, hints); } else { final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey()); DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper, true); if (diffPanel == null) { Disposer.dispose(frameWrapper); return; } if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) { diffPanel.setPatchAppliedApproximately(); } frameWrapper.setTitle(request.getWindowTitle()); DiffUtil.initDiffFrame( diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent()); new AnAction() { public void actionPerformed(final AnActionEvent e) { frameWrapper.getFrame().dispose(); } }.registerCustomShortcutSet( new CustomShortcutSet( KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent()); frameWrapper.show(); } }