mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 02:07:50 +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;
|
package org.jetbrains.tutorials.run.configuration;
|
||||||
|
|
||||||
import com.intellij.execution.configurations.*;
|
import com.intellij.execution.configurations.*;
|
||||||
|
import com.intellij.openapi.components.BaseState;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Anna Bulenkova
|
* @author Anna Bulenkova
|
||||||
@ -13,13 +16,21 @@ public class DemoConfigurationFactory extends ConfigurationFactory {
|
|||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public RunConfiguration createTemplateConfiguration(Project project) {
|
public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
|
||||||
return new DemoRunConfiguration(project, this, "Demo");
|
return new DemoRunConfiguration(project, this, "Demo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return FACTORY_NAME;
|
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.*;
|
||||||
import com.intellij.execution.configurations.*;
|
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.execution.runners.ExecutionEnvironment;
|
||||||
import com.intellij.openapi.options.SettingsEditor;
|
import com.intellij.openapi.options.SettingsEditor;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
@ -10,11 +14,25 @@ import org.jetbrains.annotations.*;
|
|||||||
/**
|
/**
|
||||||
* @author Anna Bulenkova
|
* @author Anna Bulenkova
|
||||||
*/
|
*/
|
||||||
public class DemoRunConfiguration extends RunConfigurationBase {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected DemoRunConfigurationOptions getOptions() {
|
||||||
|
return (DemoRunConfigurationOptions) super.getOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScriptName() {
|
||||||
|
return getOptions().getScriptName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScriptName(String scriptName) {
|
||||||
|
getOptions().setScriptName(scriptName);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
|
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
|
||||||
@ -28,8 +46,16 @@ public class DemoRunConfiguration extends RunConfigurationBase {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws
|
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) {
|
||||||
ExecutionException {
|
return new CommandLineState(executionEnvironment) {
|
||||||
return null;
|
@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/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<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>
|
<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">
|
<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"/>
|
<preferred-size width="-1" height="20"/>
|
||||||
|
@ -6,25 +6,21 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Anna Bulenkova
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Anna Bulenkova
|
* @author Anna Bulenkova
|
||||||
*/
|
*/
|
||||||
public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
||||||
private JPanel myPanel;
|
private JPanel myPanel;
|
||||||
private LabeledComponent<ComponentWithBrowseButton> myMainClass;
|
private LabeledComponent<TextFieldWithBrowseButton> myScriptName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) {
|
protected void resetEditorFrom(DemoRunConfiguration demoRunConfiguration) {
|
||||||
|
myScriptName.getComponent().setText(demoRunConfiguration.getScriptName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void applyEditorTo(DemoRunConfiguration demoRunConfiguration) throws ConfigurationException {
|
protected void applyEditorTo(@NotNull DemoRunConfiguration demoRunConfiguration) throws ConfigurationException {
|
||||||
|
demoRunConfiguration.setScriptName(myScriptName.getComponent().getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -34,8 +30,8 @@ public class DemoSettingsEditor extends SettingsEditor<DemoRunConfiguration> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createUIComponents() {
|
private void createUIComponents() {
|
||||||
myMainClass = new LabeledComponent<ComponentWithBrowseButton>();
|
myScriptName = new LabeledComponent<TextFieldWithBrowseButton>();
|
||||||
myMainClass.setComponent(new TextFieldWithBrowseButton());
|
myScriptName.setComponent(new TextFieldWithBrowseButton());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user