Skip to content

Commit

Permalink
add the possibility to define a "confirm dialog box"
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaillandier committed Apr 9, 2021
1 parent 02585d7 commit 416a576
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions msi.gama.core/src/msi/gama/common/interfaces/IGui.java
Expand Up @@ -99,6 +99,9 @@ public interface IGui {

Map<String, Object> openUserInputDialog(IScope scope, String title, List<IParameter> parameters, GamaFont font);

public Boolean openUserInputDialogConfirm(final IScope scope, final String title,final String message) ;


void openUserControlPanel(IScope scope, UserPanelStatement panel);

void closeDialogs(IScope scope);
Expand Down
6 changes: 6 additions & 0 deletions msi.gama.core/src/msi/gama/runtime/HeadlessListener.java
Expand Up @@ -10,6 +10,7 @@
********************************************************************************************************/
package msi.gama.runtime;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -80,6 +81,11 @@ public Map<String, Object> openUserInputDialog(final IScope scope, final String
});
return initialValues;
}

@Override
public Boolean openUserInputDialogConfirm(final IScope scope, final String title,final String message) {
return true;
}

// See #2996: simplification of the logging done in this class
// public void registerJob(final BufferedWriter w) {
Expand Down
14 changes: 14 additions & 0 deletions msi.gama.core/src/msi/gaml/operators/System.java
Expand Up @@ -273,6 +273,20 @@ public static IMap<String, Object> userInput(final IScope scope, final String ti
});
return userInput(scope, title, parameters,font);
}

@operator (
value = IKeyword.USER_CONFIRM,
category = { IOperatorCategory.SYSTEM, IOperatorCategory.USER_CONTROL },
concept = {})
@doc (
value = "Asks the user to confirm a choice. The two string are used to specify the title and the message of the dialog box. ",
examples =

{ @example ("bool confirm <- user_confirm(\"Confirm\",\"Please confirm\";") })
@no_test
public static Boolean userConfirmDialog(final IScope scope, final String title, final String message) {
return scope.getGui().openUserInputDialogConfirm(scope, title,message);
}

@SuppressWarnings ("unchecked")
@operator (
Expand Down
Expand Up @@ -431,6 +431,7 @@ public interface IKeyword {
String USER_CONTROLLED = "user_controlled";
String USER_COMMAND = "user_command";
String USER_INPUT = "user_input";
String USER_CONFIRM = "user_confirm";
String USER_ONLY = "user_only";
String USER_FIRST = "user_first";
String USER_LAST = "user_last";
Expand Down
10 changes: 10 additions & 0 deletions ummisco.gama.ui.shared/src/ummisco/gama/ui/utils/SwtGui.java
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Map;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
Expand Down Expand Up @@ -278,6 +279,15 @@ public Map<String, Object> openUserInputDialog(final IScope scope, final String
});
return result;
}

@Override
public Boolean openUserInputDialogConfirm(final IScope scope, final String title,final String message) {
final List<Boolean> result = new ArrayList<>();
WorkbenchHelper.run(() -> {
result.add(MessageDialog.openConfirm(WorkbenchHelper.getShell(), title, message));
});
return result.isEmpty() ? false : result.get(0);
}

@Override
public void openUserControlPanel(final IScope scope, final UserPanelStatement panel) {
Expand Down

0 comments on commit 416a576

Please sign in to comment.