Skip to content

Commit

Permalink
[eclipse] Make the dynamic launch configuration panel able to react t…
Browse files Browse the repository at this point in the history
…o SRE changes.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 5, 2020
1 parent df2eeff commit 512496f
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -29,6 +29,8 @@
**/io.janusproject.kernel/src/main/generated-sources
**/io.janusproject.tests/src/main/generated-sources
**/io.janusproject.tests/src/test/generated-sources
**/io.janusproject.network/src-gen/
**/io.janusproject.network/src/main/generated-sources

# Xtext templates
**/*.xml_gen
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import com.google.inject.Injector;
Expand Down Expand Up @@ -108,6 +109,7 @@ protected void setTabs(ILaunchConfigurationTab... tabs) {
* @param builder the builder that is able to fill out the list of panels. The parameter of the procedure
* is the list to fill with the panels.
* @return the list of tabs to be added into the panel, before they are injected.
* @since 0.12
* @see #setTabs(ILaunchConfigurationTab...)
*/
protected ILaunchConfigurationTab[] buildTabList(
Expand All @@ -119,10 +121,19 @@ protected ILaunchConfigurationTab[] buildTabList(

final Boolean addStandardPanels = builder.apply(list);

// Find the SARL run-time environment tab
ISarlRuntimeEnvironmentTab runtimeTab = null;
for (final ILaunchConfigurationTab tab : list) {
if (tab instanceof ISarlRuntimeEnvironmentTab) {
runtimeTab = (ISarlRuntimeEnvironmentTab) tab;
break;
}
}

final List<ISarlLaunchConfigurationPanelFactory> factories = getFactoriesFromExtension();
for (final ISarlLaunchConfigurationPanelFactory factory : factories) {
if (factory.canCreatePanel(dialog, mode, list)) {
final ILaunchConfigurationTab panel = factory.newLaunchConfigurationPanel();
if (factory.canCreatePanel(dialog, mode, list, runtimeTab)) {
final ILaunchConfigurationTab panel = factory.newLaunchConfigurationPanel(dialog, mode, list, runtimeTab);
if (panel != null) {
list.add(panel);
}
Expand Down Expand Up @@ -165,6 +176,26 @@ private static List<ISarlLaunchConfigurationPanelFactory> getFactoriesFromExtens
return Collections.emptyList();
}

/** Register the given SRE listener on any change of SRE selection into the run-time environment tab.
* This function does nothing if there is no tab for the run-time environment into the given list.
*
* @param listOfTabs is the list of the registered tabs.
* @param listeners is the list of the objects to register as listener on the SRE selection changes.
* @since 0.12
*/
protected static void addSreChangeListeners(List<ILaunchConfigurationTab> listOfTabs, ISreChangeListener... listeners) {
if (listOfTabs != null && listeners != null) {
for (final ILaunchConfigurationTab tab : listOfTabs) {
if (tab instanceof ISarlRuntimeEnvironmentTab) {
final ISarlRuntimeEnvironmentTab runtimeTab = (ISarlRuntimeEnvironmentTab) tab;
for (final ISreChangeListener listener : listeners) {
runtimeTab.addSreChangeListener(listener);
}
}
}
}
}

/** Replies the preferred tab for configuring the classpath.
* The tab may be the standard {@link JavaClasspathTab} or its specialization
* {@link JavaDependenciesTab}.
Expand Down
Expand Up @@ -39,18 +39,26 @@ public interface ISarlLaunchConfigurationPanelFactory {

/** Create the instance of the launch configuration panel.
*
* @param dialog the launch configuration panel.
* @param mode the running mode.
* @param list the list of panels that were already created.
* @param runtimeTab the reference to the runtime tab if it is added to the dialog box. It may
* be {@code null} if no run-time panel was added into the list.
* @return the instance.
*/
ILaunchConfigurationTab newLaunchConfigurationPanel();
ILaunchConfigurationTab newLaunchConfigurationPanel(ILaunchConfigurationDialog dialog, String mode,
List<ILaunchConfigurationTab> list, ISarlRuntimeEnvironmentTab runtimeTab);

/** Determine if the panel should be created with {@link #newLaunchConfigurationPanel()}.
*
* @param dialog the launch configuration panel.
* @param mode the running mode.
* @param list the list of panels that were already created.
* @param runtimeTab the reference to the runtime tab if it is added to the dialog box.
* @return {@code true} if the launch configuration panel should be created.
*/
default boolean canCreatePanel(ILaunchConfigurationDialog dialog, String mode, List<ILaunchConfigurationTab> list) {
default boolean canCreatePanel(ILaunchConfigurationDialog dialog, String mode, List<ILaunchConfigurationTab> list,
ISarlRuntimeEnvironmentTab runtimeTab) {
return true;
}

Expand Down
@@ -0,0 +1,47 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.eclipse.launching.dialog;

/**
* Interace for representing any tab for the SARL run-time environment configuration.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.12
*/
public interface ISarlRuntimeEnvironmentTab {

/** Add the listener on the SRE changes.
*
* @param listener the listener.
*/
void addSreChangeListener(ISreChangeListener listener);

/** Remove the listener on the SRE changes.
*
* @param listener the listener.
*/
void removeSreChangeListener(ISreChangeListener listener);

}
Expand Up @@ -37,13 +37,14 @@ public class SARLAgentLaunchConfigurationTabGroup extends AbstractSARLLaunchConf
@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
final ILaunchConfigurationTab[] tabs = buildTabList(dialog, mode, list -> {
final SARLAgentMainLaunchConfigurationTab mainTab = new SARLAgentMainLaunchConfigurationTab();
final SARLRuntimeEnvironmentTab sreTab = new SARLRuntimeEnvironmentTab(true);
sreTab.addSreChangeListener(mainTab);
// Add before the dynamically provided panels
final SARLAgentMainLaunchConfigurationTab mainTab = new SARLAgentMainLaunchConfigurationTab();
list.add(0, mainTab);
list.add(1, new SARLArgumentsTab());
list.add(2, sreTab);
list.add(2, new SARLRuntimeEnvironmentTab(true));

addSreChangeListeners(list, mainTab);

return true;
});
setTabs(tabs);
Expand Down
Expand Up @@ -39,13 +39,14 @@ public class SARLApplicationLaunchConfigurationTabGroup extends AbstractSARLLaun
@Override
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
final ILaunchConfigurationTab[] tabs = buildTabList(dialog, mode, list -> {
final SARLApplicationMainLaunchConfigurationTab mainTab = new SARLApplicationMainLaunchConfigurationTab();
final SARLRuntimeEnvironmentTab sreTab = new SARLRuntimeEnvironmentTab(false);
sreTab.addSreChangeListener(mainTab);
// Add before the dynamically provided panels
final SARLApplicationMainLaunchConfigurationTab mainTab = new SARLApplicationMainLaunchConfigurationTab();
list.add(0, mainTab);
list.add(1, new JavaArgumentsTab());
list.add(2, sreTab);
list.add(2, new SARLRuntimeEnvironmentTab(false));

addSreChangeListeners(list, mainTab);

return true;
});
setTabs(tabs);
Expand Down
Expand Up @@ -69,7 +69,7 @@
* @mavenartifactid $ArtifactId$
* @see JavaJRETab
*/
public class SARLRuntimeEnvironmentTab extends JavaJRETab {
public class SARLRuntimeEnvironmentTab extends JavaJRETab implements ISarlRuntimeEnvironmentTab {

private final boolean resetJvaMainClass;

Expand Down Expand Up @@ -169,15 +169,16 @@ public void fireSreChange(ISREInstall sre) {
}
}

/** Add the listener on the SRE changes.
*
* @param listener the listener.
* @since 0.11
*/
void addSreChangeListener(ISreChangeListener listener) {
@Override
public void addSreChangeListener(ISreChangeListener listener) {
this.sreChangeListeners.add(listener);
}

@Override
public void removeSreChangeListener(ISreChangeListener listener) {
this.sreChangeListeners.remove(listener);
}

/** Replies the block that permits to configure the SRE.
*
* @return the SRE configuration clock.
Expand Down Expand Up @@ -240,6 +241,7 @@ public void dispose() {
if (blk != null) {
blk.dispose();
}
this.sreChangeListeners.clear();
}

@Override
Expand Down
Expand Up @@ -21,9 +21,13 @@

package io.sarl.sre.eclipse.network;

import java.util.List;

import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;

import io.sarl.eclipse.launching.dialog.ISarlLaunchConfigurationPanelFactory;
import io.sarl.eclipse.launching.dialog.ISarlRuntimeEnvironmentTab;

/**
* Provider of the launch configuration panel for the Janus network.
Expand All @@ -37,8 +41,13 @@
public class JanusLaunchNetworkTabFactory implements ISarlLaunchConfigurationPanelFactory {

@Override
public ILaunchConfigurationTab newLaunchConfigurationPanel() {
return new JanusLaunchNetworkTab();
public ILaunchConfigurationTab newLaunchConfigurationPanel(ILaunchConfigurationDialog dialog, String mode,
List<ILaunchConfigurationTab> list, ISarlRuntimeEnvironmentTab runtimeTab) {
final JanusLaunchNetworkTab tab = new JanusLaunchNetworkTab();
/*if (runtimeTab != null) {
runtimeTab.addSreChangeListener(tab);
}*/
return tab;
}

}

0 comments on commit 512496f

Please sign in to comment.