private void recreateEditorsPanel() { myValuesPanel.removeAll(); myValuesPanel.setLayout(new CardLayout()); if (!myProject.isOpen()) return; JPanel valuesPanelComponent = new MyJPanel(new GridBagLayout()); myValuesPanel.add( new JBScrollPane(valuesPanelComponent) { @Override public void updateUI() { super.updateUI(); getViewport().setBackground(UIUtil.getPanelBackground()); } }, VALUES); myValuesPanel.add(myNoPropertySelectedPanel, NO_PROPERTY_SELECTED); List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles(); GridBagConstraints gc = new GridBagConstraints( 0, 0, 0, 0, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0); releaseAllEditors(); myTitledPanels.clear(); int y = 0; Editor previousEditor = null; Editor firstEditor = null; for (final PropertiesFile propertiesFile : propertiesFiles) { final Editor editor = createEditor(); final Editor oldEditor = myEditors.put(propertiesFile, editor); if (firstEditor == null) { firstEditor = editor; } if (previousEditor != null) { editor.putUserData( ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor); previousEditor.putUserData( ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, editor); } previousEditor = editor; if (oldEditor != null) { EditorFactory.getInstance().releaseEditor(oldEditor); } ((EditorEx) editor) .addFocusListener( new FocusChangeListener() { @Override public void focusGained(final Editor editor) { mySelectedEditor = editor; } @Override public void focusLost(final Editor eventEditor) { writeEditorPropertyValue(editor, propertiesFile, null); } }); gc.gridx = 0; gc.gridy = y++; gc.gridheight = 1; gc.gridwidth = GridBagConstraints.REMAINDER; gc.weightx = 1; gc.weighty = 1; gc.anchor = GridBagConstraints.CENTER; Locale locale = propertiesFile.getLocale(); List<String> names = new ArrayList<String>(); if (!Comparing.strEqual(locale.getDisplayLanguage(), null)) { names.add(locale.getDisplayLanguage()); } if (!Comparing.strEqual(locale.getDisplayCountry(), null)) { names.add(locale.getDisplayCountry()); } if (!Comparing.strEqual(locale.getDisplayVariant(), null)) { names.add(locale.getDisplayVariant()); } String title = propertiesFile.getName(); if (!names.isEmpty()) { title += " (" + StringUtil.join(names, "/") + ")"; } JComponent comp = new JPanel(new BorderLayout()) { @Override public Dimension getPreferredSize() { Insets insets = getBorder().getBorderInsets(this); return new Dimension(100, editor.getLineHeight() * 4 + insets.top + insets.bottom); } }; comp.add(editor.getComponent(), BorderLayout.CENTER); comp.setBorder(IdeBorderFactory.createTitledBorder(title, true)); myTitledPanels.put(propertiesFile, (JPanel) comp); valuesPanelComponent.add(comp, gc); } if (previousEditor != null) { previousEditor.putUserData( ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, firstEditor); firstEditor.putUserData( ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor); } gc.gridx = 0; gc.gridy = y; gc.gridheight = GridBagConstraints.REMAINDER; gc.gridwidth = GridBagConstraints.REMAINDER; gc.weightx = 10; gc.weighty = 1; valuesPanelComponent.add(new JPanel(), gc); selectionChanged(); myValuesPanel.repaint(); UIUtil.invokeAndWaitIfNeeded( new Runnable() { @Override public void run() { updateEditorsFromProperties(); } }); }
public void navigate(int injectedOffset) { if (myAction.isShowInBalloon()) { final JComponent component = myAction.createBalloonComponent(myNewFile); if (component != null) { final Balloon balloon = JBPopupFactory.getInstance() .createBalloonBuilder(component) .setShadow(true) .setAnimationCycle(0) .setHideOnClickOutside(true) .setHideOnKeyOutside(true) .setHideOnAction(false) .setFillColor(UIUtil.getControlColor()) .createBalloon(); new AnAction() { @Override public void actionPerformed(AnActionEvent e) { balloon.hide(); } }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, component); Disposer.register(myNewFile.getProject(), balloon); final Balloon.Position position = QuickEditAction.getBalloonPosition(myEditor); RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor); if (position == Balloon.Position.above) { final Point p = point.getPoint(); point = new RelativePoint( point.getComponent(), new Point(p.x, p.y - myEditor.getLineHeight())); } balloon.show(point, position); } } else { final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject); final FileEditor[] editors = fileEditorManager.getEditors(myNewVirtualFile); if (editors.length == 0) { final EditorWindow curWindow = fileEditorManager.getCurrentWindow(); mySplittedWindow = curWindow.split(SwingConstants.HORIZONTAL, false, myNewVirtualFile, true); } Editor editor = fileEditorManager.openTextEditor( new OpenFileDescriptor(myProject, myNewVirtualFile, injectedOffset), true); // fold missing values if (editor != null) { editor.putUserData(QuickEditAction.QUICK_EDIT_HANDLER, this); final FoldingModel foldingModel = editor.getFoldingModel(); foldingModel.runBatchFoldingOperation( () -> { for (RangeMarker o : ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) { String replacement = o.getUserData(REPLACEMENT_KEY); if (StringUtil.isEmpty(replacement)) continue; FoldRegion region = foldingModel.addFoldRegion(o.getStartOffset(), o.getEndOffset(), replacement); if (region != null) region.setExpanded(false); } }); } SwingUtilities.invokeLater( () -> myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE)); } }