com.intellij.openapi.ui.DialogBuilder Java Examples
The following examples show how to use
com.intellij.openapi.ui.DialogBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractArtifactsBeforeRunTaskProvider.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Nonnull @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, T task) { final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts(); Set<ArtifactPointer> pointers = new THashSet<>(); for (Artifact artifact : artifacts) { pointers.add(ArtifactPointerManager.getInstance(myProject).create(artifact)); } pointers.addAll(task.getArtifactPointers()); ArtifactChooser chooser = new ArtifactChooser(new ArrayList<>(pointers)); chooser.markElements(task.getArtifactPointers()); chooser.setPreferredSize(new Dimension(400, 300)); DialogBuilder builder = new DialogBuilder(myProject); builder.setTitle(CompilerBundle.message("build.artifacts.before.run.selector.title")); builder.setDimensionServiceKey("#BuildArtifactsBeforeRunChooser"); builder.addOkAction(); builder.addCancelAction(); builder.setCenterPanel(chooser); builder.setPreferredFocusComponent(chooser); AsyncResult<Void> result = builder.showAsync(); result.doWhenDone(() -> task.setArtifactPointers(chooser.getMarkedElements())); return result; }
Example #2
Source File: MergeRequestImpl.java From consulo with Apache License 2.0 | 6 votes |
private static void configureAction(DialogBuilder builder, DialogBuilder.CustomizableAction customizableAction, ActionButtonPresentation presentation) { customizableAction.setText(presentation.getName()); String actionName = presentation.getName(); final int index = actionName.indexOf('&'); final char mnemonic; if (index >= 0 && index < actionName.length() - 1) { mnemonic = actionName.charAt(index + 1); actionName = actionName.substring(0, index) + actionName.substring(index + 1); } else { mnemonic = 0; } final Action action = ((DialogBuilder.ActionDescriptor)customizableAction).getAction(builder.getDialogWrapper()); action.putValue(Action.NAME, actionName); if (mnemonic > 0) { action.putValue(Action.MNEMONIC_KEY, Integer.valueOf(mnemonic)); } }
Example #3
Source File: MergeTool.java From consulo with Apache License 2.0 | 6 votes |
private static void showDialog(MergeRequestImpl data) { DialogBuilder builder = new DialogBuilder(data.getProject()); builder.setDimensionServiceKey(data.getGroupKey()); builder.setTitle(data.getWindowTitle()); Disposable parent = Disposable.newDisposable(); builder.addDisposable(parent); MergePanel2 mergePanel = createMergeComponent(data, builder, parent); builder.setCenterPanel(mergePanel.getComponent()); builder.setPreferredFocusComponent(mergePanel.getPreferredFocusedComponent()); builder.setHelpId(data.getHelpId()); int result = builder.show(); MergeRequestImpl lastData = mergePanel.getMergeRequest(); if (lastData != null) { lastData.setResult(result); } }
Example #4
Source File: PackagesNotificationPanel.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void doShowError(String title, String description, DialogBuilder builder) { builder.setTitle(title); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setText(description); textArea.setWrapStyleWord(false); textArea.setLineWrap(true); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(textArea); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); final JPanel panel = new JPanel(new BorderLayout(10, 0)); panel.setPreferredSize(new Dimension(600, 400)); panel.add(scrollPane, BorderLayout.CENTER); panel.add(new JBLabel("Details:", Messages.getErrorIcon(), SwingConstants.LEFT), BorderLayout.NORTH); builder.setCenterPanel(panel); builder.setButtonsAlignment(SwingConstants.CENTER); builder.addOkAction(); builder.show(); }
Example #5
Source File: DateFilterPopupComponent.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(@Nonnull AnActionEvent e) { final DateFilterComponent dateComponent = new DateFilterComponent(false, DateFormatUtil.getDateFormat().getDelegate()); VcsLogDateFilter currentFilter = myFilterModel.getFilter(); if (currentFilter != null) { if (currentFilter.getBefore() != null) { dateComponent.setBefore(currentFilter.getBefore().getTime()); } if (currentFilter.getAfter() != null) { dateComponent.setAfter(currentFilter.getAfter().getTime()); } } DialogBuilder db = new DialogBuilder(DateFilterPopupComponent.this); db.addOkAction(); db.setCenterPanel(dateComponent.getPanel()); db.setPreferredFocusComponent(dateComponent.getPanel()); db.setTitle("Select Period"); if (DialogWrapper.OK_EXIT_CODE == db.show()) { long after = dateComponent.getAfter(); long before = dateComponent.getBefore(); VcsLogDateFilter filter = new VcsLogDateFilterImpl(after > 0 ? new Date(after) : null, before > 0 ? new Date(before) : null); myFilterModel.setFilter(filter); } }
Example #6
Source File: RenderingOptionsForm.java From markdown-doclet with GNU General Public License v3.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { DialogBuilder dialogBuilder = new DialogBuilder((Component)e.getSource()); dialogBuilder.setTitle("Markdown Javadoc Rendering Options"); dialogBuilder.addOkAction(); dialogBuilder.addCancelAction(); RenderingOptionsForm form = new RenderingOptionsForm(options.renderingOptions); dialogBuilder.setCenterPanel(form.getComponent()); int exitCode = dialogBuilder.show(); if (exitCode == DialogWrapper.OK_EXIT_CODE) { options.renderingOptions = form.get(); } }
Example #7
Source File: MoveToOtherStorageAction.java From markdown-image-kit with MIT License | 5 votes |
/** * 初始化 message 监听更新 ok 按钮可用状态 * * @param builder the builder * @param dialog the dialog * @param index the index */ private static void showMessage(@NotNull DialogBuilder builder, @NotNull MoveToOtherOssSettingsDialog dialog, int index) { boolean isClientEnable = OssState.getStatus(index); boolean isValidInput = StringUtils.isNotBlank(dialog.getDomain().getText()) && !DOMAIN_DEFAULT_MESSAGE.equals(dialog.getDomain().getText()); dialog.getMessage().setText(isClientEnable ? "" : "当前 OSS 不可用"); dialog.getMessage().setForeground(isClientEnable ? JBColor.WHITE : JBColor.RED); builder.setOkActionEnabled(isClientEnable && isValidInput); }
Example #8
Source File: EnvironmentVariablesTextFieldWithBrowseButton.java From consulo with Apache License 2.0 | 5 votes |
public static void showParentEnvironmentDialog(@Nonnull Component parent) { EnvVariablesTable table = new EnvVariablesTable(); table.setValues(convertToVariables(new TreeMap<>(new GeneralCommandLine().getParentEnvironment()), true)); table.getActionsPanel().setVisible(false); DialogBuilder builder = new DialogBuilder(parent); builder.setTitle(ExecutionBundle.message("environment.variables.system.dialog.title")); builder.centerPanel(table.getComponent()); builder.addCloseButton(); builder.show(); }
Example #9
Source File: VcsDiffUtil.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess public static void showChangesDialog(@Nonnull Project project, @Nonnull String title, @Nonnull List<Change> changes) { DialogBuilder dialogBuilder = new DialogBuilder(project); dialogBuilder.setTitle(title); dialogBuilder.setActionDescriptors(new DialogBuilder.CloseDialogAction()); final ChangesBrowser changesBrowser = new ChangesBrowser(project, null, changes, null, false, true, null, ChangesBrowser.MyUseCase.COMMITTED_CHANGES, null); changesBrowser.setChangesToDisplay(changes); dialogBuilder.setCenterPanel(changesBrowser); dialogBuilder.setPreferredFocusComponent(changesBrowser.getPreferredFocusedComponent()); dialogBuilder.showNotModal(); }
Example #10
Source File: BaseDiffFromHistoryHandler.java From consulo with Apache License 2.0 | 5 votes |
protected void showChangesDialog(@Nonnull String title, @Nonnull List<Change> changes) { DialogBuilder dialogBuilder = new DialogBuilder(myProject); dialogBuilder.setTitle(title); dialogBuilder.setActionDescriptors(new DialogBuilder.ActionDescriptor[]{new DialogBuilder.CloseDialogAction()}); final ChangesBrowser changesBrowser = new ChangesBrowser(myProject, null, changes, null, false, true, null, ChangesBrowser.MyUseCase.COMMITTED_CHANGES, null); changesBrowser.setChangesToDisplay(changes); dialogBuilder.setCenterPanel(changesBrowser); dialogBuilder.setPreferredFocusComponent(changesBrowser.getPreferredFocusedComponent()); dialogBuilder.showNotModal(); }
Example #11
Source File: MergeRequestImpl.java From consulo with Apache License 2.0 | 5 votes |
public void setActions(final DialogBuilder builder, MergePanel2 mergePanel, final Convertor<DialogWrapper, Boolean> preOkHook) { builder.removeAllActions(); // otherwise dialog will get default actions (OK, Cancel) if (myOkButtonPresentation != null) { if (builder.getOkAction() == null) { builder.addOkAction(); } configureAction(builder, builder.getOkAction(), myOkButtonPresentation); builder.setOkOperation(new Runnable() { @Override public void run() { if (preOkHook != null && !preOkHook.convert(builder.getDialogWrapper())) return; myOkButtonPresentation.run(builder.getDialogWrapper()); } }); } if (myCancelButtonPresentation != null) { if (builder.getCancelAction() == null) { builder.addCancelAction(); } configureAction(builder, builder.getCancelAction(), myCancelButtonPresentation); builder.setCancelOperation(new Runnable() { @Override public void run() { myCancelButtonPresentation.run(builder.getDialogWrapper()); } }); } if (getMergeContent() != null && mergePanel.getMergeList() != null) { new AllResolvedListener(mergePanel, builder.getDialogWrapper()); } }
Example #12
Source File: MergePanel2.java From consulo with Apache License 2.0 | 5 votes |
public MergePanel2(DialogBuilder builder, @Nonnull Disposable parent) { ArrayList<EditorPlace> editorPlaces = new ArrayList<EditorPlace>(); EditorPlace.EditorListener placeListener = new EditorPlace.EditorListener() { @Override public void onEditorCreated(EditorPlace place) { if (myDuringCreation) return; disposeMergeList(); myDuringCreation = true; try { tryInitView(); } finally { myDuringCreation = false; } } @Override public void onEditorReleased(Editor releasedEditor) { LOG.assertTrue(!myDuringCreation); disposeMergeList(); } }; for (int i = 0; i < EDITORS_COUNT; i++) { EditorPlace editorPlace = new EditorPlace(new DiffEditorState(i), indexToColumn(i), this); Disposer.register(parent, editorPlace); editorPlaces.add(editorPlace); editorPlace.addListener(placeListener); myEditorsPanels[i] = new LabeledComponent(); myEditorsPanels[i].setLabelLocation(BorderLayout.NORTH); myEditorsPanels[i].setComponent(editorPlace); } FontSizeSynchronizer.attachTo(editorPlaces); myPanel = new DiffPanelOuterComponent(TextDiffType.MERGE_TYPES, createToolbar()); myPanel.insertDiffComponent(new ThreePanels(myEditorsPanels, myDividers), new MyScrollingPanel()); myProvider = new MyDataProvider(); myPanel.setDataProvider(myProvider); myBuilder = builder; }
Example #13
Source File: ExecutionErrorDialog.java From consulo with Apache License 2.0 | 5 votes |
public static void show(final ExecutionException e, final String title, final Project project) { if (e instanceof RunCanceledByUserException) { return; } if (ApplicationManager.getApplication().isUnitTestMode()) { throw new RuntimeException(e.getLocalizedMessage()); } final String message = e.getMessage(); if (message == null || message.length() < 100) { Messages.showErrorDialog(project, message == null ? "exception was thrown" : message, title); return; } final DialogBuilder builder = new DialogBuilder(project); builder.setTitle(title); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); textArea.setForeground(UIUtil.getLabelForeground()); textArea.setBackground(UIUtil.getLabelBackground()); textArea.setFont(UIUtil.getLabelFont()); textArea.setText(message); textArea.setWrapStyleWord(false); textArea.setLineWrap(true); final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(textArea); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); final JPanel panel = new JPanel(new BorderLayout(10, 0)); panel.setPreferredSize(new Dimension(500, 200)); panel.add(scrollPane, BorderLayout.CENTER); panel.add(new JLabel(Messages.getErrorIcon()), BorderLayout.WEST); builder.setCenterPanel(panel); builder.setButtonsAlignment(SwingConstants.CENTER); builder.addOkAction(); builder.show(); }
Example #14
Source File: ExtractConceptInfoCollector.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
private void showDialog(String steps, ExtractConceptDialog form) { final DialogBuilder builder = new DialogBuilder(editor.getProject()); form.setData(steps, getConceptFileNames(), builder); builder.setCenterPanel(form.getRootPane()); builder.setTitle("Extract Concept"); builder.removeAllActions(); builder.show(); }
Example #15
Source File: Panel.java From GitCommitMessage with Apache License 2.0 | 5 votes |
public DialogWrapper createTemplateDialog(Project project) { Template template = new Template(project); DialogBuilder builder = new DialogBuilder(project); builder.setTitle("Git / Hg Mercurial Commit Message Template."); builder.setCenterPanel(template.getMainPanel()); builder.removeAllActions(); builder.addOkAction(); builder.addCancelAction(); boolean isOk = builder.show() == DialogWrapper.OK_EXIT_CODE; if (isOk) { TemplateFileHandler.storeFile(project, template.getTemplateContent()); } return builder.getDialogWrapper(); }
Example #16
Source File: TemplateEditPane.java From CodeMaker with Apache License 2.0 | 5 votes |
private void testTemplate() { CodeTemplate template = new CodeTemplate(getTemplateName(), getClassName(), getTemplate(), getClassNumber(), getFileEncoding(), getTemplateLanguage(), getTargetLanguage()); final List<ClassEntry> classEntries = inputClassIndices() .map(i -> getSelectedTestInput().createInput("SomeClass" + i) ) .collect(Collectors.toList()); Object result; try { result = templateEngine.evaluate(template, classEntries, classEntries.get(0)); } catch (Throwable e) { result = e; } final DialogBuilder builder = new DialogBuilder(this.templateEdit); builder.addCloseButton().setText("Close"); if(result instanceof GeneratedSource) { builder.setTitle(((GeneratedSource) result).getClassName()); builder.setCenterPanel( Editors.createSourceEditor(null, getTargetLanguage(), ((GeneratedSource) result).getContent(), true).getComponent()); } else { Throwable error = (Throwable) result; builder.setTitle("Failed!"); builder.setCenterPanel( Editors.createSourceEditor(null, "txt", error.getMessage() + "\n\n" + ExceptionUtil.getThrowableText(error), true) .getComponent()); } builder.show(); }
Example #17
Source File: CodeMakerAction.java From CodeMaker with Apache License 2.0 | 5 votes |
private void showSource(Project project, String language, String className, String content) { final Editor editor = Editors.createSourceEditor(project, language, content, true); try { final DialogBuilder builder = new DialogBuilder(project); builder.addCloseButton().setText("Close"); builder.setCenterPanel(editor.getComponent()); builder.setTitle(className); builder.show(); } finally { Editors.release(editor); } }
Example #18
Source File: DialogUtil.java From freeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 创建普通对话框 * @param message * @param okText * @param cancelText * @return */ public static boolean createDialog(String message, String okText, String cancelText) { DialogBuilder builder = new DialogBuilder(); builder.setTitle("Dialog Message"); builder.resizable(false); builder.setCenterPanel(new JLabel(message, Messages.getInformationIcon(), SwingConstants.CENTER)); builder.addOkAction().setText(okText); builder.addCancelAction().setText(cancelText); builder.setButtonsAlignment(SwingConstants.CENTER); return builder.show() == 0; }
Example #19
Source File: UsingReportAction.java From freeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void actionPerformed(AnActionEvent event) { final Project project = event.getProject(); Module[] modules = ModuleManager.getInstance(project).getModules(); List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>(); for (Module module : modules) { GradleBuildFile file = GradleBuildFile.get(module); if (file != null && !GradleUtil.isLibrary(file)) { selectModulesList.add(Pair.create(module, file.getPsiFile())); } } if (selectModulesList.size() > 1) { final DialogBuilder builder = new DialogBuilder(); builder.setTitle("Freeline Reporter"); builder.resizable(false); builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.", Messages.getInformationIcon(), SwingConstants.CENTER)); builder.addOkAction().setText("Cancel"); for (final Pair<Module, PsiFile> pair : selectModulesList) { builder.addAction(new AbstractAction(":" + pair.first.getName()) { @Override public void actionPerformed(ActionEvent e) { builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE); report(project, pair.getSecond()); } }); } if (builder.show() > -1) { //return false; } } else if (selectModulesList.size() == 1) { report(project, selectModulesList.get(0).getSecond()); } }
Example #20
Source File: CodeDialogBuilder.java From android-codegenerator-plugin-intellij with Apache License 2.0 | 5 votes |
public CodeDialogBuilder(Project project, String title, String producedCode) { dialogBuilder = new DialogBuilder(project); dialogBuilder.setTitle(title); JPanel centerPanel = new JPanel(new BorderLayout()); codeArea = prepareCodeArea(producedCode); centerPanel.add(new JBScrollPane(codeArea), BorderLayout.CENTER); dialogBuilder.setCenterPanel(centerPanel); topPanel = new JPanel(new GridLayout(0, 2)); centerPanel.add(topPanel, BorderLayout.PAGE_START); dialogBuilder.removeAllActions(); }
Example #21
Source File: ExtractConceptDialog.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
public void setData(String data, List<String> files, DialogBuilder builder) { this.builder = builder; this.steps.setColumns(50); this.steps.setRows(10); this.steps.setEditable(false); this.steps.setText(data); for (String file : files) this.files.addItem(file); }
Example #22
Source File: MergeTool.java From consulo with Apache License 2.0 | 4 votes |
private static MergePanel2 createMergeComponent(DiffRequest data, DialogBuilder builder, @Nonnull Disposable parent) { MergePanel2 mergePanel = new MergePanel2(builder, parent); mergePanel.setDiffRequest(data); return mergePanel; }
Example #23
Source File: PackagesNotificationPanel.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void showError(@NotNull Component owner, @NotNull String title, @NotNull String description) { doShowError(title, description, new DialogBuilder(owner)); }
Example #24
Source File: PackagesNotificationPanel.java From vue-for-idea with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void showError(@NotNull Project project, @NotNull String title, @NotNull String description) { doShowError(title, description, new DialogBuilder(project)); }
Example #25
Source File: MergeRequestImpl.java From consulo with Apache License 2.0 | 4 votes |
public void setActions(final DialogBuilder builder, MergePanel2 mergePanel) { setActions(builder, mergePanel, null); }
Example #26
Source File: SyncProjectDialog.java From p4ic4idea with Apache License 2.0 | 4 votes |
public SyncProjectDialog(@NotNull Project project) { this.project = project; this.directoryMapping = createDirectoryMapping(project); final UnnamedConfigurable configurable = P4Vcs.getInstance(project).getRootConfigurable(directoryMapping); if (!(configurable instanceof P4VcsRootConfigurable)) { this.setupProblem = P4Bundle.getString("checkout.config.error.invalid-project"); this.directoryField = null; this.dialog = null; this.configurable = null; return; } this.configurable = (P4VcsRootConfigurable) configurable; JComponent component = configurable.createComponent(); if (component == null) { this.setupProblem = P4Bundle.getString("checkout.config.error.invalid-project"); this.directoryField = null; this.dialog = null; return; } this.setupProblem = null; JPanel dirPanel = new JPanel(new BorderLayout()); this.directoryField = new TextFieldWithBrowseButton(); dirPanel.add(directoryField, BorderLayout.CENTER); directoryField.setButtonEnabled(true); directoryField.addBrowseFolderListener( P4Bundle.getString("checkout.config.directory.chooser.title"), P4Bundle.getString("checkout.config.directory.chooser.desc"), project, FileChooserDescriptorFactory.createSingleLocalFileDescriptor() ); JLabel dirLabel = SwingUtil.createLabelFor(P4Bundle.getString("checkout.config.directory"), directoryField); dirPanel.add(dirLabel, BorderLayout.WEST); this.dialog = new DialogBuilder(project) .centerPanel(component) .title(P4Bundle.getString("checkout.config.title")); dialog.setNorthPanel(dirPanel); }
Example #27
Source File: FrameDiffTool.java From consulo with Apache License 2.0 | 4 votes |
static void showDiffDialog(DialogBuilder builder, Collection hints) { builder.showModal(!hints.contains(DiffTool.HINT_SHOW_NOT_MODAL_DIALOG)); }
Example #28
Source File: FreelineUtil.java From freeline with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 检查是否需要载入Freeline * * @param project * @return */ public static boolean checkInstall(@NotNull final Project project) { final FreelineStatus status = getFreelineStatus(project); if (GradleUtil.isSyncInProgress(project)) { NotificationUtils.errorMsgDialog("Waiting for sync project to complete"); return false; } if (status.hasInitFreeline()) { return true; } if (status.getGradleBuildFiles().size() < 1) { NotificationUtils.errorMsgDialog("It's not an Android Gradle project Currently?"); return false; } if (status.isExistClasspath() && status.isExistPlugin() && !status.isExistFreelineCore()) { NotificationUtils.errorNotification("Execute task initFreeline and download freeline dependencies..."); initFreeline(project); return false; } if (DialogUtil.createDialog("Detected that you did not installFreeline Freeline, Whether installFreeline Automatically?", "Install Freeline Automatically", "Cancel")) { Module[] modules = ModuleManager.getInstance(project).getModules(); List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>(); for (Module module : modules) { GradleBuildFile file = GradleBuildFile.get(module); if (file != null && !GradleUtil.isLibrary(file)) { selectModulesList.add(Pair.create(module, file.getPsiFile())); } } // 多个app模块的情况 if (selectModulesList.size() > 1) { final DialogBuilder builder = new DialogBuilder(); builder.setTitle("Install Freeline"); builder.resizable(false); builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the module to be installed Freeline.", Messages.getInformationIcon(), SwingConstants.CENTER)); builder.addOkAction().setText("Cancel"); for (final Pair<Module, PsiFile> pair : selectModulesList) { builder.addAction(new AbstractAction(":" + pair.first.getName()) { @Override public void actionPerformed(ActionEvent e) { builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE); installFreeline(project, status, pair.getSecond()); } }); } if (builder.show() > -1) { return false; } } else if (selectModulesList.size() == 1) { installFreeline(project, status, selectModulesList.get(0).getSecond()); } else { NotificationUtils.errorMsgDialog("Can not found Application Module! Please Sync Project."); return false; } } return false; }
Example #29
Source File: FileTypeConfigurable.java From consulo with Apache License 2.0 | 4 votes |
private void editPattern(@Nullable final String item) { final FileType type = myRecognizedFileType.getSelectedFileType(); if (type == null) return; final String title = item == null ? FileTypesBundle.message("filetype.edit.add.pattern.title") : FileTypesBundle.message("filetype.edit.edit.pattern.title"); final Language oldLanguage = item == null ? null : myTempTemplateDataLanguages.findAssociatedFileType(item); final FileTypePatternDialog dialog = new FileTypePatternDialog(item, type, oldLanguage); final DialogBuilder builder = new DialogBuilder(myPatterns); builder.setPreferredFocusComponent(dialog.getPatternField()); builder.setCenterPanel(dialog.getMainPanel()); builder.setTitle(title); builder.showModal(true); if (builder.getDialogWrapper().isOK()) { final String pattern = dialog.getPatternField().getText(); if (StringUtil.isEmpty(pattern)) return; final FileNameMatcher matcher = FileTypeManager.parseFromString(pattern); FileType registeredFileType = findExistingFileType(matcher); if (registeredFileType != null && registeredFileType != type) { if (registeredFileType.isReadOnly()) { Messages.showMessageDialog(myPatterns.myPatternsList, FileTypesBundle .message("filetype.edit.add.pattern.exists.error", registeredFileType.getDescription()), title, Messages.getErrorIcon()); return; } else { if (Messages.OK == Messages.showOkCancelDialog(myPatterns.myPatternsList, FileTypesBundle .message("filetype.edit.add.pattern.exists.message", registeredFileType.getDescription()), FileTypesBundle.message("filetype.edit.add.pattern.exists.title"), FileTypesBundle.message("filetype.edit.add.pattern.reassign.button"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon())) { myTempPatternsTable.removeAssociation(matcher, registeredFileType); if(oldLanguage != null) { myTempTemplateDataLanguages.removeAssociation(matcher, oldLanguage); } myReassigned.put(matcher, registeredFileType); } else { return; } } } if (item != null) { final FileNameMatcher oldMatcher = FileTypeManager.parseFromString(item); myTempPatternsTable.removeAssociation(oldMatcher, type); if(oldLanguage != null) { myTempTemplateDataLanguages.removeAssociation(oldMatcher, oldLanguage); } } myTempPatternsTable.addAssociation(matcher, type); myTempTemplateDataLanguages.addAssociation(matcher, dialog.getTemplateDataLanguage()); updateExtensionList(); final int index = myPatterns.getListModel().indexOf(matcher.getPresentableString()); if (index >= 0) { ScrollingUtil.selectItem(myPatterns.myPatternsList, index); } IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myPatterns.myPatternsList); } }
Example #30
Source File: MemoryDiskConflictResolver.java From consulo with Apache License 2.0 | 4 votes |
boolean askReloadFromDisk(VirtualFile file, Document document) { if (myConflictAppeared != null) { Throwable trace = myConflictAppeared; myConflictAppeared = null; throw new IllegalStateException("Unexpected memory-disk conflict in tests for " + file.getPath() + ", please use FileDocumentManager#reloadFromDisk or avoid VFS refresh", trace); } String message = UIBundle.message("file.cache.conflict.message.text", file.getPresentableUrl()); DialogBuilder builder = new DialogBuilder(); 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) { Project project = ProjectLocator.getInstance().guessProjectForFile(file); String fsContent = LoadTextUtil.loadText(file).toString(); DocumentContent content1 = DiffContentFactory.getInstance().create(project, fsContent, file.getFileType()); DocumentContent content2 = DiffContentFactory.getInstance().create(project, document, file); String title = UIBundle.message("file.cache.conflict.for.file.dialog.title", file.getPresentableUrl()); String title1 = UIBundle.message("file.cache.conflict.diff.content.file.system.content"); String title2 = UIBundle.message("file.cache.conflict.diff.content.memory.content"); DiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2); request.putUserData(DiffUserDataKeys.GO_TO_SOURCE_DISABLE, true); DialogBuilder diffBuilder = new DialogBuilder(project); DiffRequestPanel diffPanel = DiffManager.getInstance().createRequestPanel(project, diffBuilder, diffBuilder.getWindow()); diffPanel.setRequest(request); diffBuilder.setCenterPanel(diffPanel.getComponent()); diffBuilder.setDimensionServiceKey("FileDocumentManager.FileCacheConflict"); 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; }