-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32520 from vespa-engine/interns/magnus/intellij-j…
…ava-path feat: setting to set java path in IntelliJ plugin
- Loading branch information
Showing
5 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...er/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ai.vespa.schemals.intellij.settings; | ||
|
||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.components.PersistentStateComponent; | ||
import com.intellij.openapi.components.State; | ||
import com.intellij.openapi.components.Storage; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* This is the 'Model' part of the Settings interface per MVC. | ||
* It simply contains the current settings state. | ||
*/ | ||
@State( | ||
name = "ai.vespa.schemals.intellij.settings.SchemaLspSettings", | ||
storages = @Storage("VespaSchemaSettings.xml") | ||
) | ||
public final class SchemaSettings implements PersistentStateComponent<SchemaSettings.State> { | ||
public static class State { | ||
@NonNls | ||
public String javaPath = ""; | ||
} | ||
|
||
private State state = new State(); | ||
|
||
public static SchemaSettings getInstance() { | ||
return ApplicationManager.getApplication() | ||
.getService(SchemaSettings.class); | ||
} | ||
|
||
@Override | ||
public State getState() { | ||
return state; | ||
} | ||
|
||
@Override | ||
public void loadState(@NotNull State state) { | ||
this.state = state; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...s/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ai.vespa.schemals.intellij.settings; | ||
|
||
import com.intellij.openapi.fileChooser.FileChooserDescriptor; | ||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; | ||
import com.intellij.openapi.fileChooser.FileChooserPanel; | ||
import com.intellij.openapi.ui.TextFieldWithBrowseButton; | ||
import com.intellij.openapi.util.ThrowableComputable; | ||
import com.intellij.ui.components.JBLabel; | ||
import com.intellij.ui.components.JBTextField; | ||
import com.intellij.util.ui.FormBuilder; | ||
import com.jetbrains.JBRFileDialog; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
/** | ||
* This is the 'View' part of the Settings interface per MVC | ||
* It defines the settings ui for the plugin. | ||
*/ | ||
public class SchemaSettingsComponent { | ||
private final JPanel mainPanel; | ||
private final TextFieldWithBrowseButton javaPathTextField = new TextFieldWithBrowseButton(); | ||
|
||
public SchemaSettingsComponent() { | ||
FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); | ||
fileChooserDescriptor.setTitle("Select Path to Java Home"); | ||
javaPathTextField.addBrowseFolderListener("Java Path", "Select path to java home", null, fileChooserDescriptor); | ||
javaPathTextField.setToolTipText("Path to Java Home or directory containing a java executable. Will use the system installed version of java if not set."); | ||
|
||
mainPanel = FormBuilder.createFormBuilder() | ||
.addLabeledComponent(new JBLabel("Path to java home:"), javaPathTextField, 1, false) | ||
.addComponentFillVertically(new JPanel(), 0) | ||
.getPanel(); | ||
} | ||
|
||
public JPanel getPanel() { | ||
return mainPanel; | ||
} | ||
|
||
public JComponent getPreferredFocusedComponent() { | ||
return javaPathTextField; | ||
} | ||
|
||
@NotNull | ||
public String getJavaPathText() { | ||
return javaPathTextField.getText(); | ||
} | ||
|
||
public void setJavaPathText(@NotNull String javaPath) { | ||
javaPathTextField.setText(javaPath); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...ntellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ai.vespa.schemals.intellij.settings; | ||
|
||
import com.intellij.openapi.options.Configurable; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.util.Objects; | ||
|
||
/** | ||
* This is the 'Controller' part of the Settings interface per MVC | ||
* It glues the ui and the state together and interacts with the IntelliJ platform. | ||
*/ | ||
public class SchemaSettingsConfigurable implements Configurable { | ||
private SchemaSettingsComponent settingsComponent; | ||
|
||
@Nls(capitalization = Nls.Capitalization.Title) | ||
@Override | ||
public String getDisplayName() { | ||
return "Vespa Schema Settings"; | ||
} | ||
|
||
@Override | ||
public JComponent getPreferredFocusedComponent() { | ||
return settingsComponent.getPreferredFocusedComponent(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JComponent createComponent() { | ||
settingsComponent = new SchemaSettingsComponent(); | ||
return settingsComponent.getPanel(); | ||
} | ||
|
||
@Override | ||
public boolean isModified() { | ||
SchemaSettings.State state = | ||
Objects.requireNonNull(SchemaSettings.getInstance().getState()); | ||
return !settingsComponent.getJavaPathText().equals(state.javaPath); | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
SchemaSettings.State state = | ||
Objects.requireNonNull(SchemaSettings.getInstance().getState()); | ||
state.javaPath = settingsComponent.getJavaPathText(); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
SchemaSettings.State state = | ||
Objects.requireNonNull(SchemaSettings.getInstance().getState()); | ||
settingsComponent.setJavaPathText(state.javaPath); | ||
} | ||
|
||
@Override | ||
public void disposeUIResources() { | ||
settingsComponent = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters