mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
Execution API docs (#1065)
This commit is contained in:
parent
f0919033ea
commit
952dcd552e
@ -23,7 +23,8 @@ public class DemoConfigurationFactory extends ConfigurationFactory {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
|
public RunConfiguration createTemplateConfiguration(
|
||||||
|
@NotNull Project project) {
|
||||||
return new DemoRunConfiguration(project, this, "Demo");
|
return new DemoRunConfiguration(project, this, "Demo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||||
|
|
||||||
package org.jetbrains.sdk.runConfiguration;
|
package org.jetbrains.sdk.runConfiguration;
|
||||||
|
|
||||||
import com.intellij.execution.ExecutionException;
|
import com.intellij.execution.ExecutionException;
|
||||||
@ -17,7 +16,9 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class DemoRunConfiguration extends RunConfigurationBase<DemoRunConfigurationOptions> {
|
public class DemoRunConfiguration extends RunConfigurationBase<DemoRunConfigurationOptions> {
|
||||||
|
|
||||||
protected DemoRunConfiguration(Project project, ConfigurationFactory factory, String name) {
|
protected DemoRunConfiguration(Project project,
|
||||||
|
ConfigurationFactory factory,
|
||||||
|
String name) {
|
||||||
super(project, factory, name);
|
super(project, factory, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,19 +42,18 @@ public class DemoRunConfiguration extends RunConfigurationBase<DemoRunConfigurat
|
|||||||
return new DemoSettingsEditor();
|
return new DemoSettingsEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void checkConfiguration() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) {
|
public RunProfileState getState(@NotNull Executor executor,
|
||||||
return new CommandLineState(executionEnvironment) {
|
@NotNull ExecutionEnvironment environment) {
|
||||||
|
return new CommandLineState(environment) {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected ProcessHandler startProcess() throws ExecutionException {
|
protected ProcessHandler startProcess() throws ExecutionException {
|
||||||
GeneralCommandLine commandLine = new GeneralCommandLine(getOptions().getScriptName());
|
GeneralCommandLine commandLine =
|
||||||
OSProcessHandler processHandler = ProcessHandlerFactory.getInstance().createColoredProcessHandler(commandLine);
|
new GeneralCommandLine(getOptions().getScriptName());
|
||||||
|
OSProcessHandler processHandler = ProcessHandlerFactory.getInstance()
|
||||||
|
.createColoredProcessHandler(commandLine);
|
||||||
ProcessTerminatedListener.attach(processHandler);
|
ProcessTerminatedListener.attach(processHandler);
|
||||||
return processHandler;
|
return processHandler;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ import com.intellij.openapi.components.StoredProperty;
|
|||||||
|
|
||||||
public class DemoRunConfigurationOptions extends RunConfigurationOptions {
|
public class DemoRunConfigurationOptions extends RunConfigurationOptions {
|
||||||
|
|
||||||
private final StoredProperty<String> myScriptName = string("").provideDelegate(this, "scriptName");
|
private final StoredProperty<String> myScriptName =
|
||||||
|
string("").provideDelegate(this, "scriptName");
|
||||||
|
|
||||||
public String getScriptName() {
|
public String getScriptName() {
|
||||||
return myScriptName.getValue(this);
|
return myScriptName.getValue(this);
|
||||||
|
@ -1,43 +1,18 @@
|
|||||||
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||||
|
|
||||||
package org.jetbrains.sdk.runConfiguration;
|
package org.jetbrains.sdk.runConfiguration;
|
||||||
|
|
||||||
import com.intellij.execution.configurations.ConfigurationFactory;
|
import com.intellij.execution.configurations.ConfigurationTypeBase;
|
||||||
import com.intellij.execution.configurations.ConfigurationType;
|
|
||||||
import com.intellij.icons.AllIcons;
|
import com.intellij.icons.AllIcons;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import com.intellij.openapi.util.NotNullLazyValue;
|
||||||
|
|
||||||
import javax.swing.*;
|
public class DemoRunConfigurationType extends ConfigurationTypeBase {
|
||||||
|
|
||||||
public class DemoRunConfigurationType implements ConfigurationType {
|
|
||||||
|
|
||||||
static final String ID = "DemoRunConfiguration";
|
static final String ID = "DemoRunConfiguration";
|
||||||
|
|
||||||
@NotNull
|
protected DemoRunConfigurationType() {
|
||||||
@Override
|
super(ID, "Demo", "Demo run configuration type",
|
||||||
public String getDisplayName() {
|
NotNullLazyValue.createValue(() -> AllIcons.Nodes.Console));
|
||||||
return "Demo";
|
addFactory(new DemoConfigurationFactory(this));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getConfigurationTypeDescription() {
|
|
||||||
return "Demo run configuration type";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Icon getIcon() {
|
|
||||||
return AllIcons.General.Information;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConfigurationFactory[] getConfigurationFactories() {
|
|
||||||
return new ConfigurationFactory[]{new DemoConfigurationFactory(this)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.sdk.runConfiguration.DemoSettingsEditor">
|
|
||||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
|
||||||
<constraints>
|
|
||||||
<xy x="20" y="20" width="500" height="400"/>
|
|
||||||
</constraints>
|
|
||||||
<properties/>
|
|
||||||
<border type="none"/>
|
|
||||||
<children>
|
|
||||||
<component id="57eab" class="com.intellij.openapi.ui.LabeledComponent" binding="myScriptName" custom-create="true">
|
|
||||||
<constraints>
|
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
|
||||||
<preferred-size width="-1" height="20"/>
|
|
||||||
</grid>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<labelLocation value="West"/>
|
|
||||||
<text value="Script file"/>
|
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<vspacer id="93bd6">
|
|
||||||
<constraints>
|
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</vspacer>
|
|
||||||
</children>
|
|
||||||
</grid>
|
|
||||||
</form>
|
|
@ -1,27 +1,36 @@
|
|||||||
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||||
|
|
||||||
package org.jetbrains.sdk.runConfiguration;
|
package org.jetbrains.sdk.runConfiguration;
|
||||||
|
|
||||||
|
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||||
import com.intellij.openapi.options.SettingsEditor;
|
import com.intellij.openapi.options.SettingsEditor;
|
||||||
import com.intellij.openapi.ui.LabeledComponent;
|
|
||||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||||
|
import com.intellij.util.ui.FormBuilder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
||||||
|
|
||||||
private JPanel myPanel;
|
private final JPanel myPanel;
|
||||||
private LabeledComponent<TextFieldWithBrowseButton> myScriptName;
|
private final TextFieldWithBrowseButton scriptPathField;
|
||||||
|
|
||||||
|
public DemoSettingsEditor() {
|
||||||
|
scriptPathField = new TextFieldWithBrowseButton();
|
||||||
|
scriptPathField.addBrowseFolderListener("Select Script File", null, null,
|
||||||
|
FileChooserDescriptorFactory.createSingleFileDescriptor());
|
||||||
|
myPanel = FormBuilder.createFormBuilder()
|
||||||
|
.addLabeledComponent("Script file", scriptPathField)
|
||||||
|
.getPanel();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) {
|
protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) {
|
||||||
myScriptName.getComponent().setText(demoRunConfiguration.getScriptName());
|
scriptPathField.setText(demoRunConfiguration.getScriptName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void applyEditorTo(@NotNull DemoRunConfiguration demoRunConfiguration) {
|
protected void applyEditorTo(@NotNull DemoRunConfiguration demoRunConfiguration) {
|
||||||
demoRunConfiguration.setScriptName(myScriptName.getComponent().getText());
|
demoRunConfiguration.setScriptName(scriptPathField.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -30,9 +39,4 @@ public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
|||||||
return myPanel;
|
return myPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUIComponents() {
|
|
||||||
myScriptName = new LabeledComponent<>();
|
|
||||||
myScriptName.setComponent(new TextFieldWithBrowseButton());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user