Search in sources :

Example 1 with SplitterProportionsData

use of com.intellij.openapi.ui.SplitterProportionsData in project intellij-community by JetBrains.

the class ContentChooser method dispose.

@Override
public void dispose() {
    super.dispose();
    SplitterProportionsData d = new SplitterProportionsDataImpl();
    d.externalizeToDimensionService(getClass().getName());
    d.saveSplitterProportions(mySplitter);
    if (myViewer != null) {
        EditorFactory.getInstance().releaseEditor(myViewer);
        myViewer = null;
    }
}
Also used : SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl)

Example 2 with SplitterProportionsData

use of com.intellij.openapi.ui.SplitterProportionsData in project intellij-community by JetBrains.

the class InjectionsSettingsUI method doImportAction.

private void doImportAction(final DataContext dataContext) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return file.getFileType() == StdFileTypes.XML;
        }
    };
    descriptor.setDescription("Please select the configuration file (usually named IntelliLang.xml) to import.");
    descriptor.setTitle("Import Configuration");
    descriptor.putUserData(LangDataKeys.MODULE_CONTEXT, LangDataKeys.MODULE.getData(dataContext));
    final SplitterProportionsData splitterData = new SplitterProportionsDataImpl();
    splitterData.externalizeFromDimensionService("IntelliLang.ImportSettingsKey.SplitterProportions");
    final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
    if (file == null)
        return;
    try {
        final Configuration cfg = Configuration.load(file.getInputStream());
        if (cfg == null) {
            Messages.showWarningDialog(myProject, "The selected file does not contain any importable configuration.", "Nothing to Import");
            return;
        }
        final CfgInfo info = getDefaultCfgInfo();
        final Map<String, Set<InjInfo>> currentMap = ContainerUtil.classify(info.injectionInfos.iterator(), new Convertor<InjInfo, String>() {

            public String convert(final InjInfo o) {
                return o.injection.getSupportId();
            }
        });
        final List<BaseInjection> originalInjections = new ArrayList<>();
        final List<BaseInjection> newInjections = new ArrayList<>();
        for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
            ArrayList<InjInfo> list = new ArrayList<>(ObjectUtils.notNull(currentMap.get(supportId), Collections.<InjInfo>emptyList()));
            final List<BaseInjection> currentInjections = getInjectionList(list);
            final List<BaseInjection> importingInjections = cfg.getInjections(supportId);
            if (currentInjections == null) {
                newInjections.addAll(importingInjections);
            } else {
                Configuration.importInjections(currentInjections, importingInjections, originalInjections, newInjections);
            }
        }
        info.replace(originalInjections, newInjections);
        myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
        final int n = newInjections.size();
        if (n > 1) {
            Messages.showInfoMessage(myProject, n + " entries have been successfully imported", "Import Successful");
        } else if (n == 1) {
            Messages.showInfoMessage(myProject, "One entry has been successfully imported", "Import Successful");
        } else {
            Messages.showInfoMessage(myProject, "No new entries have been imported", "Import");
        }
    } catch (Exception ex) {
        Configuration.LOG.error(ex);
        final String msg = ex.getLocalizedMessage();
        Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Import Failed");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) THashSet(gnu.trove.THashSet) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) IOException(java.io.IOException) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 3 with SplitterProportionsData

use of com.intellij.openapi.ui.SplitterProportionsData in project intellij-community by JetBrains.

the class ContentChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION;
    myList.setSelectionMode(selectionMode);
    if (myUseIdeaEditor) {
        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
        myList.setFont(scheme.getFont(EditorFontType.PLAIN));
        Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), new JBColor(UIUtil::getListForeground));
        Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), new JBColor(UIUtil::getListBackground));
        myList.setForeground(fg);
        myList.setBackground(bg);
    }
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            close(OK_EXIT_CODE);
            return true;
        }
    }.installOn(myList);
    MyListCellRenderer renderer = new MyListCellRenderer();
    myList.setCellRenderer(renderer);
    myList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                int newSelectionIndex = -1;
                for (Object o : myList.getSelectedValuesList()) {
                    int i = ((Item) o).index;
                    removeContentAt(myAllContents.get(i));
                    if (newSelectionIndex < 0) {
                        newSelectionIndex = i;
                    }
                }
                rebuildListContent();
                if (myAllContents.isEmpty()) {
                    close(CANCEL_EXIT_CODE);
                    return;
                }
                newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1);
                myList.setSelectedIndex(newSelectionIndex);
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                doOKAction();
            } else {
                SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myList);
                if (supply != null && supply.isPopupActive())
                    return;
                char aChar = e.getKeyChar();
                if (aChar >= '0' && aChar <= '9') {
                    int idx = aChar == '0' ? 9 : aChar - '1';
                    if (idx < myAllContents.size()) {
                        myList.setSelectedIndex(idx);
                        e.consume();
                        doOKAction();
                    }
                }
            }
        }
    });
    mySplitter.setFirstComponent(ListWithFilter.wrap(myList, ScrollPaneFactory.createScrollPane(myList), o -> o.getShortText(renderer.previewChars)));
    mySplitter.setSecondComponent(new JPanel());
    mySplitter.getFirstComponent().addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            FontMetrics metrics = myList.getFontMetrics(myList.getFont());
            int charWidth = metrics.charWidth('m');
            renderer.previewChars = myList.getParent().getParent().getWidth() / charWidth + 10;
        }
    });
    rebuildListContent();
    ScrollingUtil.installActions(myList);
    ScrollingUtil.ensureSelectionExists(myList);
    updateViewerForSelection();
    myList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (myUpdateAlarm.isDisposed())
                return;
            myUpdateAlarm.cancelAllRequests();
            myUpdateAlarm.addRequest(() -> updateViewerForSelection(), 100);
        }
    });
    mySplitter.setPreferredSize(JBUI.size(500, 500));
    SplitterProportionsData d = new SplitterProportionsDataImpl();
    d.externalizeToDimensionService(getClass().getName());
    d.restoreSplitterProportions(mySplitter);
    return mySplitter;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) JBIterable(com.intellij.util.containers.JBIterable) Document(com.intellij.openapi.editor.Document) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) ListWithFilter(com.intellij.ui.speedSearch.ListWithFilter) ArrayList(java.util.ArrayList) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBUI(com.intellij.util.ui.JBUI) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) com.intellij.ui(com.intellij.ui) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) java.awt.event(java.awt.event) EditorFactory(com.intellij.openapi.editor.EditorFactory) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Aggregations

SplitterProportionsDataImpl (com.intellij.ide.ui.SplitterProportionsDataImpl)3 SplitterProportionsData (com.intellij.openapi.ui.SplitterProportionsData)3 CommonBundle (com.intellij.CommonBundle)1 AllIcons (com.intellij.icons.AllIcons)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 EditorFontType (com.intellij.openapi.editor.colors.EditorFontType)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Project (com.intellij.openapi.project.Project)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 com.intellij.ui (com.intellij.ui)1 JBList (com.intellij.ui.components.JBList)1 FilteringListModel (com.intellij.ui.speedSearch.FilteringListModel)1 ListWithFilter (com.intellij.ui.speedSearch.ListWithFilter)1 SpeedSearchSupply (com.intellij.ui.speedSearch.SpeedSearchSupply)1