Skip to content

Commit

Permalink
[sre] Complete the launch configuration panel for the network features.
Browse files Browse the repository at this point in the history
see #1027

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 6, 2020
1 parent 1fa6090 commit abac031
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 40 deletions.
Expand Up @@ -7,9 +7,11 @@ Bundle-Version: 0.12.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: io.janusproject.plugin;bundle-version="0.12.0";visibility:=reexport,
io.sarl.eclipse;bundle-version="0.12.0",
io.janusproject.network;bundle-version="0.12.0",
io.sarl.api.bootiquebase;bundle-version="0.12.0",
org.eclipse.jdt.core;bundle-version="3.22.0",
org.eclipse.core.runtime;bundle-version="3.18.0",
org.arakhne.afc.bootique.variables;bundle-version="16.0.0",
org.eclipse.ui.workbench;bundle-version="3.119.0",
org.eclipse.jdt.ui;bundle-version="3.21.100",
org.eclipse.debug.ui;bundle-version="3.14.500",
Expand All @@ -20,10 +22,12 @@ Require-Bundle: io.janusproject.plugin;bundle-version="0.12.0";visibility:=reexp
com.fasterxml.jackson.core.jackson-core;bundle-version="2.11.0",
com.fasterxml.jackson.core.jackson-databind;bundle-version="2.11.0",
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;bundle-version="2.11.0",
javax.inject;bundle-version="1.0.0"
javax.inject;bundle-version="1.0.0",
org.eclipse.help
Bundle-Activator: io.sarl.sre.eclipse.JanusEclipsePlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Export-Package: io.sarl.sre.eclipse,
io.sarl.sre.eclipse.buildpath,
io.sarl.sre.eclipse.network,
io.sarl.sre.eclipse.sre
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -24,6 +24,9 @@
import com.google.common.base.Strings;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ResourceLocator;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

/**
Expand All @@ -32,7 +35,6 @@
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*
*/
public class JanusEclipsePlugin extends AbstractUIPlugin {

Expand Down Expand Up @@ -160,4 +162,33 @@ public IStatus createOkStatus() {
return Status.OK_STATUS;
}

/** Replies the image stored in the current Eclipse plugin.
*
* @param imagePath path of the image.
* @return the image.
*/
public Image getImage(String imagePath) {
final ImageDescriptor descriptor = getImageDescriptor(imagePath);
if (descriptor == null) {
return null;
}
return descriptor.createImage();
}

/** Replies the image descriptor for the given image path.
*
* @param imagePath path of the image.
* @return the image descriptor.
*/
public ImageDescriptor getImageDescriptor(String imagePath) {
ImageDescriptor descriptor = getImageRegistry().getDescriptor(imagePath);
if (descriptor == null) {
descriptor = ResourceLocator.imageDescriptorFromBundle(PLUGIN_ID, imagePath).orElse(null);
if (descriptor != null) {
getImageRegistry().put(imagePath, descriptor);
}
}
return descriptor;
}

}
Expand Up @@ -21,18 +21,34 @@

package io.sarl.sre.eclipse.network;

import javax.inject.Inject;

import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

import io.sarl.eclipse.launching.config.ILaunchConfigurationAccessor;
import io.sarl.eclipse.launching.config.ILaunchConfigurationConfigurator;
import io.sarl.eclipse.launching.config.LaunchConfigurationUtils;
import io.sarl.eclipse.launching.config.LaunchConfigurationUtils.InputExtraJreArguments;
import io.sarl.eclipse.launching.config.LaunchConfigurationUtils.OutputExtraJreArguments;
import io.sarl.sre.eclipse.JanusEclipsePlugin;
import io.sarl.sre.network.boot.configs.SreNetworkConfig;

/**
* Configuration tab for the JRE and the SARL runtime environment.
*
Expand All @@ -44,10 +60,30 @@
*/
public class JanusLaunchNetworkTab extends JavaLaunchTab {

/** Identifier of the contributor for the launch configuration.
*/
public static final String CONTRIBUTOR_ID = "io.sarl.sre.network"; //$NON-NLS-1$

private Button enableNetworkButton;

private Label clusterNameLabel;

private Text clusterNameText;

private Label minClusterSizeLabel;

private Spinner minClusterSizeSpinner;

private Button portAutoIncrementButton;

private final WidgetListener defaultListener = new WidgetListener();

@Inject
private ILaunchConfigurationConfigurator configurator;

@Inject
private ILaunchConfigurationAccessor accessor;

/** Construct the tab for configuration of the SRE networking feature.
*/
public JanusLaunchNetworkTab() {
Expand All @@ -59,66 +95,106 @@ public String getName() {
return Messages.JanusLaunchNetworkTab_0;
}

@Override
public Image getImage() {
return JanusEclipsePlugin.getDefault().getImage("/icons/lan-network-icon.png");
}

@Override
public String getId() {
return "io.sarl.sre.eclipse.network.janusLaunchNetworkTab"; //$NON-NLS-1$
}

private static Spinner createSpinner(Composite parent, int hspan, int min, int max, int increment, int pageIncrement) {
Spinner spinner = new Spinner(parent, SWT.SINGLE | SWT.BORDER);
spinner.setFont(parent.getFont());
spinner.setMinimum(min);
spinner.setMaximum(max);
spinner.setIncrement(increment);
spinner.setPageIncrement(pageIncrement);
spinner.setDigits(0);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = hspan;
spinner.setLayoutData(gd);
return spinner;
}

@Override
public void createControl(Composite parent) {
final Font font = parent.getFont();
final Composite topComp = SWTFactory.createComposite(parent, font, 1, 1, GridData.FILL_HORIZONTAL, 0, 0);
final Composite topComp = SWTFactory.createComposite(parent, parent.getFont(), 2, 1, GridData.FILL_HORIZONTAL, 5, 5);

this.enableNetworkButton = createCheckButton(topComp, Messages.JanusLaunchNetworkTab_1);
this.enableNetworkButton = SWTFactory.createCheckButton(topComp, Messages.JanusLaunchNetworkTab_1, null, false, 2);
this.enableNetworkButton.addSelectionListener(this.defaultListener);

createSeparator(parent, 2);

this.clusterNameLabel = SWTFactory.createLabel(topComp, Messages.JanusLaunchNetworkTab_2, 1);
this.clusterNameText = SWTFactory.createSingleText(topComp, 1);
this.clusterNameText.addModifyListener(this.defaultListener);

this.minClusterSizeLabel = SWTFactory.createLabel(topComp, Messages.JanusLaunchNetworkTab_3, 1);
this.minClusterSizeSpinner = createSpinner(topComp, 1, 1, 1000, 1, 1);
this.minClusterSizeSpinner.addModifyListener(this.defaultListener);

this.portAutoIncrementButton = SWTFactory.createCheckButton(topComp, Messages.JanusLaunchNetworkTab_4, null, false, 2);
this.portAutoIncrementButton.addSelectionListener(this.defaultListener);

setControl(topComp);
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpContextId());
updateComponentStates();
}

@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
/** Update the states of the components (enabling).
*/
protected void updateComponentStates() {
final boolean enable = this.enableNetworkButton.getSelection();
this.clusterNameLabel.setEnabled(enable);
this.clusterNameText.setEnabled(enable);
this.minClusterSizeLabel.setEnabled(enable);
this.minClusterSizeSpinner.setEnabled(enable);
this.portAutoIncrementButton.setEnabled(enable);
}

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
super.initializeFrom(configuration);
final InputExtraJreArguments arguments = LaunchConfigurationUtils.createInputExtraJreArguments(CONTRIBUTOR_ID);
arguments.read(configuration, this.accessor);
this.enableNetworkButton.setSelection(arguments.arg(SreNetworkConfig.ENABLE_NAME, SreNetworkConfig.DEFAULT_ENABLE_VALUE));
this.clusterNameText.setText(arguments.arg(SreNetworkConfig.CLUSTER_NAME_NAME, SreNetworkConfig.DEFAULT_CLUSTER_NAME_VALUE));
this.minClusterSizeSpinner.setSelection(arguments.arg(SreNetworkConfig.MIN_CLUSTER_SIZE_NAME, SreNetworkConfig.DEFAULT_MIN_CLUSTER_SIZE_VALUE));
this.portAutoIncrementButton.setSelection(arguments.arg(SreNetworkConfig.PORT_AUTO_INCREMENT_NAME, SreNetworkConfig.DEFAULT_PORT_AUTO_INCREMENT_VALUE));
updateComponentStates();
}

@Override
public void dispose() {
super.dispose();
}

@Override
public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
super.activated(workingCopy);
}

@Override
public boolean isValid(ILaunchConfiguration config) {
return true;
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
final OutputExtraJreArguments arguments = LaunchConfigurationUtils.createOutputExtraJreArguments(CONTRIBUTOR_ID);
arguments.arg(SreNetworkConfig.ENABLE_NAME, SreNetworkConfig.DEFAULT_ENABLE_VALUE);
arguments.arg(SreNetworkConfig.CLUSTER_NAME_NAME, SreNetworkConfig.DEFAULT_CLUSTER_NAME_VALUE);
arguments.arg(SreNetworkConfig.MIN_CLUSTER_SIZE_NAME, SreNetworkConfig.DEFAULT_MIN_CLUSTER_SIZE_VALUE);
arguments.arg(SreNetworkConfig.PORT_AUTO_INCREMENT_NAME, SreNetworkConfig.DEFAULT_PORT_AUTO_INCREMENT_VALUE);
arguments.apply(config, this.configurator);
}

@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
//
final OutputExtraJreArguments arguments = LaunchConfigurationUtils.createOutputExtraJreArguments(CONTRIBUTOR_ID);
arguments.arg(SreNetworkConfig.ENABLE_NAME, this.enableNetworkButton.getSelection());
arguments.arg(SreNetworkConfig.CLUSTER_NAME_NAME, this.clusterNameText.getText());
arguments.arg(SreNetworkConfig.MIN_CLUSTER_SIZE_NAME, this.minClusterSizeSpinner.getSelection());
arguments.arg(SreNetworkConfig.PORT_AUTO_INCREMENT_NAME, this.portAutoIncrementButton.getSelection());
arguments.apply(configuration, this.configurator);
}

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
//
}


/** Listener of events in internal components for refreshing the tab.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
private class WidgetListener implements SelectionListener {
private class WidgetListener implements SelectionListener, ModifyListener {

WidgetListener() {
//
Expand All @@ -132,6 +208,14 @@ public void widgetDefaultSelected(SelectionEvent event) {
@SuppressWarnings("synthetic-access")
@Override
public void widgetSelected(SelectionEvent event) {
if (event.getSource() == JanusLaunchNetworkTab.this.enableNetworkButton) {
updateComponentStates();
}
updateLaunchConfigurationDialog();
}

@Override
public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
}

Expand Down
Expand Up @@ -36,6 +36,9 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = Messages.class.getPackage().getName() + ".messages"; //$NON-NLS-1$
public static String JanusLaunchNetworkTab_0;
public static String JanusLaunchNetworkTab_1;
public static String JanusLaunchNetworkTab_2;
public static String JanusLaunchNetworkTab_3;
public static String JanusLaunchNetworkTab_4;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
@@ -1,2 +1,5 @@
JanusLaunchNetworkTab_0=Networking
JanusLaunchNetworkTab_1=Enable SRE communication over the computer network
JanusLaunchNetworkTab_2=Cluster name:
JanusLaunchNetworkTab_3=Minimal size of the cluster:
JanusLaunchNetworkTab_4=Auto-incrementation of the socket port numbers
19 changes: 10 additions & 9 deletions sre/io.janusproject/io.janusproject.feature/feature.xml
Expand Up @@ -224,22 +224,31 @@
<requires>
<import plugin="io.sarl.core" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.util" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.api.naming" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.api.probing" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.api.bootiquebase" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.bootique" version="1.1.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.bootique.variables" version="16.0.0" match="greaterOrEqual"/>
<import plugin="com.google.inject" version="4.2.3" match="greaterOrEqual"/>
<import plugin="javax.inject" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi" version="3.15.300" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtend.lib" version="2.22.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.vmutils" version="16.0.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.util" version="16.0.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.inputoutput" version="16.0.0" match="greaterOrEqual"/>
<import plugin="com.fasterxml.jackson.core.jackson-annotations" version="2.11.0" match="greaterOrEqual"/>
<import plugin="io.janusproject.plugin" version="0.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi" version="3.15.100" match="greaterOrEqual"/>
<import plugin="io.bootique" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.bootique.log4j" version="16.0.0" match="greaterOrEqual"/>
<import plugin="com.hazelcast" version="4.0.3" match="greaterOrEqual"/>
<import plugin="io.sarl.eclipse" version="0.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.core" version="3.22.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.runtime" version="3.18.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.workbench" version="3.119.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.ui" version="3.21.100" match="greaterOrEqual"/>
<import plugin="org.eclipse.debug.ui" version="3.14.500" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.debug.ui" version="3.11.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.jface" version="3.20.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.swt" version="3.114.100" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.launching" version="3.17.100" match="greaterOrEqual"/>
Expand All @@ -249,15 +258,7 @@
<import plugin="org.eclipse.xtext.xbase.lib" version="2.22.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.xtend.lib.macro"/>
<import plugin="io.sarl.lang.core" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.api.naming" version="0.12.0" match="greaterOrEqual"/>
<import plugin="io.sarl.api.probing" version="0.12.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.vmutils" version="16.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.debug.ui" version="3.14.500" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.debug.ui" version="3.11.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi" version="3.15.100" match="greaterOrEqual"/>
<import plugin="io.bootique" version="1.0.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.bootique.log4j" version="16.0.0" match="greaterOrEqual"/>
<import plugin="com.hazelcast" version="4.0.3" match="greaterOrEqual"/>
<import plugin="io.janusproject.network" version="0.12.0" match="greaterOrEqual"/>
</requires>

<plugin
Expand Down
Expand Up @@ -195,8 +195,7 @@ class SreConfigModule extends AbstractModule {
binder.extend.addOption(OptionMetadata.builder(CLASSPATH_SHORT_OPTION, cpDescription)
.valueRequired(Messages::SreConfigModule_1)
.build)
.mapConfigPath(CLASSPATH_SHORT_OPTION, CLASSPATH_NAME)

.mapConfigPath(CLASSPATH_SHORT_OPTION, CLASSPATH_NAME)
}

/** Replies the instance of the SRE configuration.
Expand Down

0 comments on commit abac031

Please sign in to comment.