Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
deadok22 committed Feb 7, 2015
1 parent 6d14165 commit 5c8d776
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ErlangRemoteDebugRunConfiguration extends ErlangRunConfigurationBas
private String myRemoteErlangNodeName;
private boolean myUseShortNames = true; // controls whether to use -name or -sname for specifying local node name
private String myCookie;
private String myLongNameHost;
private String myHost;

public ErlangRemoteDebugRunConfiguration(Project project, String name) {
super(name, new ErlangModuleBasedConfiguration(project), ErlangRemoteDebugRunConfigurationType.getInstance().getConfigurationFactories()[0]);
Expand Down Expand Up @@ -77,12 +77,12 @@ public void setCookie(String cookie) {
myCookie = cookie;
}

public String getLongNameHost() {
return myLongNameHost;
public String getHost() {
return myHost;
}

public void setLongNameHost(String longNameHost) {
myLongNameHost = longNameHost;
public void setHost(String host) {
myHost = host;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import org.intellij.erlang.runconfig.ErlangRunningState;
import org.jetbrains.annotations.NotNull;
import java.net.InetAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

Expand Down Expand Up @@ -68,30 +69,26 @@ public ConsoleView createConsoleView(Executor executor) {

@Override
protected List<String> getErlFlags() {
String nodeNameFlag;
String nodeName = "debugger_node_" + System.currentTimeMillis();

if (myConfiguration.isUseShortNames()) {
nodeNameFlag = "-sname";
return ContainerUtil.list("-sname", getNodeName());
}
else {
nodeNameFlag = "-name";

//Find the host part of the name
String longNameHost = myConfiguration.getLongNameHost();
if (longNameHost==null || longNameHost.equals("")) {
try {
InetAddress addr = InetAddress.getLocalHost();
longNameHost = addr.getCanonicalHostName();
}
catch(UnknownHostException e) {
longNameHost = "127.0.0.1";
}
}
String host = StringUtil.nullize(myConfiguration.getHost(), true);
String qualifiedName = getNodeName() + "@" + (host == null ? getDefaultHost() : host);
return ContainerUtil.list("-name", qualifiedName);
}

nodeName = nodeName + "@" + longNameHost;
}
@NotNull
private static String getNodeName() {
return "debugger_node_" + System.currentTimeMillis();
}

return ContainerUtil.list(nodeNameFlag, nodeName);
@NotNull
private static String getDefaultHost() {
try {
return InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException ignore) {
}
return "127.0.0.1";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@
</constraints>
<properties/>
</component>
<component id="47150" class="javax.swing.JTextField" binding="myLongNameHostTextField">
<component id="47150" class="javax.swing.JTextField" binding="myHostTextField">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="cb618" class="javax.swing.JLabel">
<component id="cb618" class="javax.swing.JLabel" binding="myHostLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="47150"/>
<text value="&amp;Long name host:"/>
<toolTipText value="The host part of the long name. Defaults to the system hostname"/>
<text value="&amp;Host:"/>
<toolTipText value="The host part of a generated host name. Defaults to the system hostname"/>
</properties>
</component>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public class ErlangRemoteDebugConfigurationEditorForm extends ErlangDebuggableRu
private JTextField myCookieTextField;
private JCheckBox myUseShortNamesCheckBox;
private HideableTitledPanel myDebugOptionsPanel;
private JTextField myLongNameHostTextField;
private JTextField myHostTextField;
private JLabel myHostLabel;

public ErlangRemoteDebugConfigurationEditorForm() {
myUseShortNamesCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
myLongNameHostTextField.setEnabled(!myUseShortNamesCheckBox.isSelected());
setUseShortNames(myUseShortNamesCheckBox.isSelected());
}
});
}
Expand All @@ -53,8 +54,8 @@ protected void doResetEditorFrom(ErlangRemoteDebugRunConfiguration configuration
myNodeTextField.setText(configuration.getRemoteErlangNodeName());
myCookieTextField.setText(configuration.getCookie());
myUseShortNamesCheckBox.setSelected(configuration.isUseShortNames());
myLongNameHostTextField.setEnabled(!myUseShortNamesCheckBox.isSelected());
myLongNameHostTextField.setText(configuration.getLongNameHost());
myHostTextField.setText(configuration.getHost());
setUseShortNames(myUseShortNamesCheckBox.isSelected());
}

@Override
Expand All @@ -63,7 +64,7 @@ protected void doApplyEditorTo(ErlangRemoteDebugRunConfiguration configuration)
configuration.setRemoteErlangNodeName(myNodeTextField.getText());
configuration.setCookie(myCookieTextField.getText());
configuration.setUseShortNames(myUseShortNamesCheckBox.isSelected());
configuration.setLongNameHost(myLongNameHostTextField.getText());
configuration.setHost(myHostTextField.getText());
}

@NotNull
Expand All @@ -76,4 +77,9 @@ private void createUIComponents() {
myDebugOptionsPanel = createDebugOptionsHideablePanel();
myDebugOptionsPanel.setOn(true);
}

private void setUseShortNames(boolean b) {
myHostLabel.setVisible(!b);
myHostTextField.setVisible(!b);
}
}

0 comments on commit 5c8d776

Please sign in to comment.