Skip to content

Commit

Permalink
Merge branch 'redhat-developer:main' into issue_638
Browse files Browse the repository at this point in the history
  • Loading branch information
SCWells72 authored Dec 1, 2024
2 parents d25e2c7 + dfd27f9 commit 25068d5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ private JPanel createSettings(JComponent description, boolean launchingServerDef
launchingServerDefinition ? LanguageServerPanel.EditionMode.EDIT_USER_DEFINED :
LanguageServerPanel.EditionMode.EDIT_EXTENSION, project);
this.mappingPanel = languageServerPanel.getMappingsPanel();
return builder
.addComponentFillVertically(new JPanel(), 50)
.getPanel();
return builder.getPanel();
}

private JComponent createDescription(String description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package com.redhat.devtools.lsp4ij.settings.ui;

import com.intellij.ui.AnActionButton;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.ui.AnActionButtonRunnable;
import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.table.TableView;
Expand Down Expand Up @@ -44,6 +44,7 @@ public AbstractServerMappingTablePanel(ColumnInfo<ServerMappingSettings, String>
new ArrayList<>(),
0);
table = new TableView<>(model);
table.setColumnSelectionAllowed(true);

ToolbarDecorator toolbar = ToolbarDecorator.createDecorator(table)
.setAddAction(addData())
Expand All @@ -61,25 +62,26 @@ public List<ServerMappingSettings> getServerMappings() {
}

private AnActionButtonRunnable addData() {
return new AnActionButtonRunnable() {
@Override
public void run(AnActionButton anActionButton) {
ServerMappingSettings newMapping = createServerMappingSettings();
table.getListTableModel().addRow(newMapping);
fireStateChanged();
}
return anActionButton -> {
ServerMappingSettings newMapping = createServerMappingSettings();
table.getListTableModel().addRow(newMapping);
fireStateChanged();
// Immediately select the first cell in the new row
ApplicationManager.getApplication().invokeLater(() -> {
int newRowIndex = table.getRowCount() - 1;
table.getSelectionModel().setSelectionInterval(newRowIndex, newRowIndex);
table.getColumnModel().getSelectionModel().setSelectionInterval(0, 0);
table.requestFocusInWindow();
});
};
}

protected abstract ServerMappingSettings createServerMappingSettings();

private AnActionButtonRunnable removeData() {
return new AnActionButtonRunnable() {
@Override
public void run(AnActionButton anActionButton) {
table.getListTableModel().removeRow(table.getSelectedRow());
fireStateChanged();
}
return anActionButton -> {
table.getListTableModel().removeRow(table.getSelectedRow());
fireStateChanged();
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.lsp4ij.settings.ui;

import com.intellij.lang.Language;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.SpellCheckingEditorCustomizationProvider;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.project.Project;
import com.intellij.ui.*;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Wrapper for EditorTextField configured for JSON.
*/
public class JsonTextField extends JPanel {

private static final String JSON_LANGUAGE_NAME = "JSON";
private static final String DEFAULT_VALUE = "{}";

private final EditorTextField editorTextField;

public JsonTextField(@NotNull Project project) {
// Create and initialize the editor text field
EditorTextFieldProvider service = ApplicationManager.getApplication().getService(EditorTextFieldProvider.class);
List<EditorCustomization> features = new ArrayList<>();
ContainerUtil.addAllNotNull(features, Arrays.asList(
MonospaceEditorCustomization.getInstance(),
SoftWrapsEditorCustomization.ENABLED,
SpellCheckingEditorCustomizationProvider.getInstance().getEnabledCustomization()
));
Language jsonLanguage = Language.findLanguageByID(JSON_LANGUAGE_NAME);
if (jsonLanguage == null) {
jsonLanguage = PlainTextFileType.INSTANCE.getLanguage();
}
editorTextField = service.getEditorField(jsonLanguage, project, features);
editorTextField.setOneLineMode(false);
editorTextField.setText(DEFAULT_VALUE);

// Add it to this panel
setLayout(new BorderLayout());
add(editorTextField, BorderLayout.CENTER);
}

// Proxy some simple accessors to the editor text field

public void setText(@NotNull String text) {
editorTextField.setText(text);
}

public @NotNull String getText() {
return editorTextField.getText();
}

public void setCaretPosition(int position) {
editorTextField.setCaretPosition(position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
******************************************************************************/
package com.redhat.devtools.lsp4ij.settings.ui;

import com.intellij.ui.components.JBTextArea;
import com.intellij.util.ui.JBFont;
import com.redhat.devtools.lsp4ij.LanguageServerBundle;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

/**
* Language server configuration widget used to fill the configuration expected by the language server.
*/
public class LanguageServerConfigurationWidget extends JBTextArea {

public LanguageServerConfigurationWidget() {
super(5, 0);
super.setLineWrap(true);
super.setWrapStyleWord(true);
super.setFont(JBFont.regular());
super.getEmptyText().setText(LanguageServerBundle.message("language.server.configuration.emptyText"));
public class LanguageServerConfigurationWidget extends JsonTextField {
public LanguageServerConfigurationWidget(@NotNull Project project) {
super(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
******************************************************************************/
package com.redhat.devtools.lsp4ij.settings.ui;

import com.intellij.ui.components.JBTextArea;
import com.intellij.util.ui.JBFont;
import com.redhat.devtools.lsp4ij.LanguageServerBundle;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

/**
* Language server LSP 'Initialize Options' widget used to fill the LSP 'Initialization Options' expected by the language server.
*/
public class LanguageServerInitializationOptionsWidget extends JBTextArea {

public LanguageServerInitializationOptionsWidget() {
super(5, 0);
super.setLineWrap(true);
super.setWrapStyleWord(true);
super.setFont(JBFont.regular());
super.getEmptyText().setText(LanguageServerBundle.message("language.server.initializationOptions.emptyText"));
public class LanguageServerInitializationOptionsWidget extends JsonTextField {
public LanguageServerInitializationOptionsWidget(@NotNull Project project) {
super(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public LanguageServerPanel(FormBuilder builder, JComponent description, EditionM

private void createUI(FormBuilder builder, JComponent description, EditionMode mode) {
JBTabbedPane tabbedPane = new JBTabbedPane();
builder.addComponent(tabbedPane);
builder.addComponentFillVertically(tabbedPane, 0);

// Server tab
addServerTab(tabbedPane, description, mode);
Expand Down Expand Up @@ -180,7 +180,7 @@ private static FormBuilder addTab(JBTabbedPane tabbedPane, String tabTitle, bool
if (addToTop) {
tabPanel.addToTop(builder.getPanel());
} else {
tabPanel.add(builder.getPanel());
tabPanel.addToCenter(builder.getPanel());
}
tabbedPane.add(tabTitle, tabPanel);
return builder;
Expand Down Expand Up @@ -250,16 +250,14 @@ private static JLabel createLabelForComponent(@NotNull @NlsContexts.Label String
}

private void createConfigurationField(FormBuilder builder) {
configurationWidget = new LanguageServerConfigurationWidget();
configurationWidget = new LanguageServerConfigurationWidget(project);
JBScrollPane scrollPane = new JBScrollPane(configurationWidget);
scrollPane.setMinimumSize(new Dimension(JBUIScale.scale(600), JBUIScale.scale(100)));
builder.addLabeledComponent(LanguageServerBundle.message("language.server.configuration"), scrollPane, true);
}

private void createInitializationOptionsTabField(FormBuilder builder) {
initializationOptionsWidget = new LanguageServerInitializationOptionsWidget();
initializationOptionsWidget = new LanguageServerInitializationOptionsWidget(project);
JBScrollPane scrollPane = new JBScrollPane(initializationOptionsWidget);
scrollPane.setMinimumSize(new Dimension(JBUIScale.scale(600), JBUIScale.scale(100)));
builder.addLabeledComponent(LanguageServerBundle.message("language.server.initializationOptions"), scrollPane, true);
}

Expand Down

0 comments on commit 25068d5

Please sign in to comment.