mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +08:00
Run configuration sample actually does something functional
This commit is contained in:
parent
ceb5bb3507
commit
cdb57d20e5
@ -1,7 +1,10 @@
|
||||
package org.jetbrains.tutorials.run.configuration;
|
||||
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.openapi.components.BaseState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Anna Bulenkova
|
||||
@ -13,13 +16,21 @@ public class DemoConfigurationFactory extends ConfigurationFactory {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
||||
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
|
||||
return new DemoRunConfiguration(project, this, "Demo");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return FACTORY_NAME;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Class<? extends BaseState> getOptionsClass() {
|
||||
return DemoRunConfigurationOptions.class;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package org.jetbrains.tutorials.run.configuration;
|
||||
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.process.ProcessHandlerFactory;
|
||||
import com.intellij.execution.process.ProcessTerminatedListener;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@ -10,11 +14,25 @@ import org.jetbrains.annotations.*;
|
||||
/**
|
||||
* @author Anna Bulenkova
|
||||
*/
|
||||
public class DemoRunConfiguration extends RunConfigurationBase {
|
||||
public class DemoRunConfiguration extends RunConfigurationBase<DemoRunConfigurationOptions> {
|
||||
protected DemoRunConfiguration(Project project, ConfigurationFactory factory, String name) {
|
||||
super(project, factory, name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected DemoRunConfigurationOptions getOptions() {
|
||||
return (DemoRunConfigurationOptions) super.getOptions();
|
||||
}
|
||||
|
||||
public String getScriptName() {
|
||||
return getOptions().getScriptName();
|
||||
}
|
||||
|
||||
public void setScriptName(String scriptName) {
|
||||
getOptions().setScriptName(scriptName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
|
||||
@ -28,8 +46,16 @@ public class DemoRunConfiguration extends RunConfigurationBase {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws
|
||||
ExecutionException {
|
||||
return null;
|
||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) {
|
||||
return new CommandLineState(executionEnvironment) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected ProcessHandler startProcess() throws ExecutionException {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine(getOptions().getScriptName());
|
||||
OSProcessHandler processHandler = ProcessHandlerFactory.getInstance().createColoredProcessHandler(commandLine);
|
||||
ProcessTerminatedListener.attach(processHandler);
|
||||
return processHandler;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package org.jetbrains.tutorials.run.configuration;
|
||||
|
||||
import com.intellij.execution.configurations.RunConfigurationOptions;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class DemoRunConfigurationOptions extends RunConfigurationOptions {
|
||||
private String myScriptName;
|
||||
|
||||
public String getScriptName() {
|
||||
return myScriptName;
|
||||
}
|
||||
|
||||
public void setScriptName(String myScriptName) {
|
||||
this.myScriptName = myScriptName;
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="57eab" class="com.intellij.openapi.ui.LabeledComponent" binding="myMainClass" custom-create="true">
|
||||
<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"/>
|
||||
|
@ -6,25 +6,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Anna Bulenkova
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Anna Bulenkova
|
||||
*/
|
||||
public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
||||
private JPanel myPanel;
|
||||
private LabeledComponent<ComponentWithBrowseButton> myMainClass;
|
||||
private LabeledComponent<TextFieldWithBrowseButton> myScriptName;
|
||||
|
||||
@Override
|
||||
protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) {
|
||||
|
||||
myScriptName.getComponent().setText(demoRunConfiguration.getScriptName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyEditorTo(DemoRunConfiguration demoRunConfiguration) throws ConfigurationException {
|
||||
|
||||
protected void applyEditorTo(@NotNull DemoRunConfiguration demoRunConfiguration) throws ConfigurationException {
|
||||
demoRunConfiguration.setScriptName(myScriptName.getComponent().getText());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -34,8 +30,8 @@ public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
myMainClass = new LabeledComponent<ComponentWithBrowseButton>();
|
||||
myMainClass.setComponent(new TextFieldWithBrowseButton());
|
||||
myScriptName = new LabeledComponent<TextFieldWithBrowseButton>();
|
||||
myScriptName.setComponent(new TextFieldWithBrowseButton());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user