/
SwtGui.java
734 lines (642 loc) · 23.3 KB
/
SwtGui.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
/*******************************************************************************************************
*
* ummisco.gama.ui.utils.SwtGui.java, in plugin ummisco.gama.ui.shared, is part of the source code of the GAMA modeling
* and simulation platform (v. 1.8.1)
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/SU & Partners
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package ummisco.gama.ui.utils;
import java.awt.EventQueue;
import java.util.ArrayList;
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;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.services.ISourceProviderService;
import msi.gama.application.workbench.PerspectiveHelper;
import msi.gama.application.workbench.PerspectiveHelper.SimulationPerspectiveDescriptor;
import msi.gama.common.interfaces.IConsoleDisplayer;
import msi.gama.common.interfaces.IDisplayCreator.DisplayDescription;
import msi.gama.common.interfaces.IDisplaySurface;
import msi.gama.common.interfaces.IGamaView;
import msi.gama.common.interfaces.IGamaView.Error;
import msi.gama.common.interfaces.IGamaView.Parameters;
import msi.gama.common.interfaces.IGamaView.Test;
import msi.gama.common.interfaces.IGamaView.User;
import msi.gama.common.interfaces.IGamlLabelProvider;
import msi.gama.common.interfaces.IGui;
import msi.gama.common.interfaces.IKeyword;
import msi.gama.common.interfaces.IRuntimeExceptionHandler;
import msi.gama.common.interfaces.IStatusDisplayer;
import msi.gama.common.preferences.GamaPreferences;
import msi.gama.kernel.experiment.ExperimentAgent;
import msi.gama.kernel.experiment.IExperimentController;
import msi.gama.kernel.experiment.IExperimentPlan;
import msi.gama.kernel.experiment.IParameter;
import msi.gama.kernel.model.IModel;
import msi.gama.kernel.simulation.SimulationAgent;
import msi.gama.metamodel.agent.IAgent;
import msi.gama.metamodel.shape.ILocation;
import msi.gama.metamodel.shape.IShape;
import msi.gama.outputs.ExperimentOutputManager;
import msi.gama.outputs.IDisplayOutput;
import msi.gama.outputs.InspectDisplayOutput;
import msi.gama.outputs.LayeredDisplayOutput;
import msi.gama.runtime.GAMA;
import msi.gama.runtime.IScope;
import msi.gama.runtime.ISimulationStateProvider;
import msi.gama.runtime.exceptions.GamaRuntimeException;
import msi.gama.util.GamaFont;
import msi.gama.util.GamaListFactory;
import msi.gama.util.GamaMapFactory;
import msi.gama.util.IList;
import msi.gama.util.IMap;
import msi.gama.util.file.IFileMetaDataProvider;
import msi.gaml.architecture.user.UserPanelStatement;
import msi.gaml.compilation.Symbol;
import msi.gaml.statements.test.CompoundSummary;
import msi.gaml.statements.test.TestExperimentSummary;
import ummisco.gama.dev.utils.DEBUG;
import ummisco.gama.ui.dialogs.Messages;
import ummisco.gama.ui.interfaces.IDisplayLayoutManager;
import ummisco.gama.ui.interfaces.IModelRunner;
import ummisco.gama.ui.interfaces.IOpenGLInitializer;
import ummisco.gama.ui.interfaces.IRefreshHandler;
import ummisco.gama.ui.interfaces.ISpeedDisplayer;
import ummisco.gama.ui.interfaces.IUserDialogFactory;
import ummisco.gama.ui.parameters.EditorsDialog;
import ummisco.gama.ui.parameters.GamaWizard;
import ummisco.gama.ui.parameters.GamaWizardDialog;
import ummisco.gama.ui.parameters.GamaWizardPage;
/**
* Written by drogoul Modified on 6 mai 2011
*
* @todo Description
*
*/
public class SwtGui implements IGui {
static {
DEBUG.ON();
}
public volatile static boolean ALL_TESTS_RUNNING;
private IAgent highlightedAgent;
private ILocation mouseLocationInModel;
static {
// GamaFonts.setLabelFont(PreferencesHelper.BASE_BUTTON_FONT.getValue());
PreferencesHelper.initialize();
}
public SwtGui() {}
@Override
public boolean confirmClose(final IExperimentPlan exp) {
if (exp == null || !GamaPreferences.Runtime.CORE_ASK_CLOSING.getValue()) { return true; }
PerspectiveHelper.switchToSimulationPerspective();
return Messages.question("Close simulation confirmation", "Do you want to close experiment '" + exp.getName()
+ "' of model '" + exp.getModel().getName() + "' ?");
}
@Override
public void tell(final String msg) {
Messages.tell(msg);
}
@Override
public void error(final String err) {
Messages.error(err);
}
@Override
public void runtimeError(final IScope scope, final GamaRuntimeException g) {
if (g.isReported()) { return; }
if (GAMA.getFrontmostController() != null && GAMA.getFrontmostController().isDisposing()) { return; }
final IRuntimeExceptionHandler handler = getRuntimeExceptionHandler();
if (!handler.isRunning()) {
handler.start();
}
handler.offer(g);
g.setReported();
}
@Override
public void displayErrors(final IScope scope, final List<GamaRuntimeException> exceptions) {
if (exceptions == null) {
WorkbenchHelper.hideView(ERROR_VIEW_ID);
} else {
final IGamaView.Error v = (Error) showView(scope, ERROR_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
if (v != null) {
v.displayErrors();
}
}
}
@Override
public IGamaView.Test openTestView(final IScope scope, final boolean allTests) {
ALL_TESTS_RUNNING = allTests;
final IGamaView.Test v = (Test) showView(scope, TEST_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
if (v != null) {
v.startNewTestSequence(allTests);
}
return v;
}
@Override
public void displayTestsResults(final IScope scope, final CompoundSummary<?, ?> summary) {
final IGamaView.Test v = (Test) WorkbenchHelper.getPage().findView(TEST_VIEW_ID);
if (v != null) {
v.addTestResult(summary);
}
}
@Override
public void endTestDisplay() {
final IGamaView.Test v = (Test) WorkbenchHelper.getPage().findView(TEST_VIEW_ID);
if (v != null) {
v.finishTestSequence();
}
WorkbenchHelper.getService(IRefreshHandler.class).refreshNavigator();
}
@Override
public void clearErrors(final IScope scope) {
final IRuntimeExceptionHandler handler = getRuntimeExceptionHandler();
handler.clearErrors();
}
private Object internalShowView(final String viewId, final String secondaryId, final int code) {
if (GAMA.getFrontmostController() != null && GAMA.getFrontmostController().isDisposing()) { return null; }
final Object[] result = new Object[1];
WorkbenchHelper.run(() -> {
try {
final IWorkbenchPage page = WorkbenchHelper.getPage();
if (page != null) {
page.zoomOut();
final String second = secondaryId == null ? null
: secondaryId + "@@@" + String.valueOf(System.currentTimeMillis());
// The goal here is to address #2441 by randomizing the ids of views.
// DEBUG.LOG("Opening view " + viewId + " " + second);
result[0] = page.showView(viewId, second, code);
}
} catch (final Exception e) {
result[0] = e;
}
});
return result[0];
}
@Override
public boolean copyToClipboard(final String text) {
WorkbenchHelper.asyncRun(() -> {
final Clipboard clipboard = new Clipboard(WorkbenchHelper.getDisplay());
final TextTransfer textTransfer = TextTransfer.getInstance();
final Transfer[] transfers = new Transfer[] { textTransfer };
final Object[] data = new Object[] { text };
clipboard.setContents(data, transfers);
clipboard.dispose();
});
return true;
}
@Override
public void openWelcomePage(final boolean ifEmpty) {
WebHelper.openWelcomePage(ifEmpty);
}
@Override
public IGamaView showView(final IScope scope, final String viewId, final String secondaryId, final int code) {
Object o = internalShowView(viewId, secondaryId, code);
if (o instanceof IWorkbenchPart) {
if (o instanceof IGamaView) { return (IGamaView) o; }
o = GamaRuntimeException.error("Impossible to open view " + viewId, GAMA.getRuntimeScope());
}
if (o instanceof Throwable) {
GAMA.reportError(GAMA.getRuntimeScope(), GamaRuntimeException.create((Exception) o, GAMA.getRuntimeScope()),
false);
}
return null;
}
public void hideMonitorView() {
final IGamaView m = (IGamaView) WorkbenchHelper.findView(MONITOR_VIEW_ID, null, false);
if (m != null) {
m.reset();
WorkbenchHelper.hideView(MONITOR_VIEW_ID);
}
}
@Override
public final boolean openSimulationPerspective(final IModel model, final String experimentName) {
return PerspectiveHelper.openSimulationPerspective(model, experimentName);
}
@Override
public DisplayDescription getDisplayDescriptionFor(final String name) {
return DISPLAYS.get(name);
}
@Override
public IDisplaySurface getDisplaySurfaceFor(final LayeredDisplayOutput output, final Object... args) {
IDisplaySurface surface = null;
final String keyword = output.getData().getDisplayType();
final DisplayDescription creator = DISPLAYS.get(keyword);
if (creator != null) {
surface = creator.create(output, args);
surface.outputReloaded();
} else {
throw GamaRuntimeException.error("Display " + keyword + " is not defined anywhere.", output.getScope());
}
return surface;
}
@Override
public Map<String, Object> openUserInputDialog(final IScope scope, final String title,
final List<IParameter> parameters, final GamaFont font) {
final IMap<String, Object> result = GamaMapFactory.createUnordered();
for (final IParameter p : parameters) {
result.put(p.getName(), p.getInitialValue(scope));
}
WorkbenchHelper.run(() -> {
final EditorsDialog dialog = new EditorsDialog(scope, WorkbenchHelper.getShell(), parameters, title, font);
if (dialog.open() == Window.OK) {
result.putAll(dialog.getValues());
}
});
return result;
}
@Override
public IList<IMap<String, Object>> openWizard(IScope scope, String title, IList<IMap<String, Object>> pages) {
final IList<IMap<String, Object>> result = GamaListFactory.create();
final IList<GamaWizardPage> wizardPages = GamaListFactory.create();
for (IMap<String, Object> l : pages) {
GamaFont f = (GamaFont) l.get(IKeyword.FONT);
String t = (String) l.get(IKeyword.TITLE);
String d = (String) l.get(IKeyword.DESCRIPTION);
List<IParameter> ps = (List<IParameter>) l.get(IKeyword.PARAMETERS);
wizardPages.add(new GamaWizardPage(scope, ps,t,d, f));
}
WorkbenchHelper.run(() -> {
final GamaWizard wizard = new GamaWizard(title, wizardPages);
GamaWizardDialog wizardDialog = new GamaWizardDialog(WorkbenchHelper.getShell(),wizard);
if (wizardDialog.open() == Window.OK) {
result.addAll(wizardDialog.getValues());
}
});
return result;
}
/*@Override
public Map<String, Object> openWizard(final IScope scope, final String title,
final List<IParameter> parameters, final GamaFont font) {
final IMap<String, Object> result = GamaMapFactory.createUnordered();
for (final IParameter p : parameters) {
result.put(p.getName(), p.getInitialValue(scope));
}
WorkbenchHelper.run(() -> {
final EditorsDialog dialog = new EditorsDialog(scope, WorkbenchHelper.getShell(), parameters, title, font);
if (dialog.open() == Window.OK) {
result.putAll(dialog.getValues());
}
});
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) {
WorkbenchHelper.run(() -> {
IGamaView.User part = null;
part = (User) showView(scope, USER_CONTROL_VIEW_ID, null, IWorkbenchPage.VIEW_CREATE);
if (part != null) {
part.initFor(scope, panel);
}
scope.setOnUserHold(true);
try {
WorkbenchHelper.getPage().showView(USER_CONTROL_VIEW_ID);
} catch (final PartInitException e) {
e.printStackTrace();
}
});
}
@Override
public void closeDialogs(final IScope scope) {
WorkbenchHelper.run(() -> {
final IUserDialogFactory userDialogFactory = WorkbenchHelper.getService(IUserDialogFactory.class);
if (userDialogFactory != null) {
userDialogFactory.closeUserDialog();
}
WorkbenchHelper.hideView(USER_CONTROL_VIEW_ID);
});
}
@Override
public IAgent getHighlightedAgent() {
return highlightedAgent;
}
@Override
public void setHighlightedAgent(final IAgent a) {
highlightedAgent = a;
}
private IModelRunner getModelRunner() {
return WorkbenchHelper.getService(IModelRunner.class);
}
@Override
public void editModel(final IScope scope, final Object eObject) {
final IModelRunner modelRunner = getModelRunner();
if (modelRunner == null) { return; }
modelRunner.editModel(eObject);
}
@Override
public List<TestExperimentSummary> runHeadlessTests(final Object model) {
final IModelRunner modelRunner = getModelRunner();
if (modelRunner == null) { return null; }
return modelRunner.runHeadlessTests(model);
}
@Override
public void updateParameterView(final IScope scope, final IExperimentPlan exp) {
WorkbenchHelper.run(() -> {
if (!exp.hasParametersOrUserCommands()) { return; }
final IGamaView.Parameters view =
(Parameters) showView(scope, PARAMETER_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
view.addItem(exp);
view.updateItemValues();
});
}
@Override
public void showParameterView(final IScope scope, final IExperimentPlan exp) {
WorkbenchHelper.run(() -> {
if (!exp.hasParametersOrUserCommands()) { return; }
final IGamaView.Parameters view =
(Parameters) showView(scope, PARAMETER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
if (view != null) {
view.addItem(exp);
}
});
}
/**
* Method setSelectedAgent()
*
* @see msi.gama.common.interfaces.IGui#setSelectedAgent(msi.gama.metamodel.agent.IAgent)
*/
@Override
public void setSelectedAgent(final IAgent a) {
WorkbenchHelper.asyncRun(() -> {
if (WorkbenchHelper.getPage() == null) { return; }
if (a == null) { return; }
try {
final InspectDisplayOutput output = new InspectDisplayOutput(a);
output.launch(a.getScope());
} catch (final GamaRuntimeException g) {
g.addContext("In opening the agent inspector");
GAMA.reportError(GAMA.getRuntimeScope(), g, false);
}
final IViewReference r = WorkbenchHelper.getPage().findViewReference(IGui.AGENT_VIEW_ID, "");
if (r != null) {
WorkbenchHelper.getPage().bringToTop(r.getPart(true));
}
});
}
@Override
public void prepareForExperiment(final IScope scope, final IExperimentPlan exp) {
if (exp.isGui()) {
// hideScreen();
final IOpenGLInitializer initializer = WorkbenchHelper.getService(IOpenGLInitializer.class);
if (initializer != null && !initializer.isDone()) {
initializer.run();
}
WorkbenchHelper.setWorkbenchWindowTitle(exp.getName() + " - " + exp.getModel().getFilePath());
final ExperimentAgent agent = exp.getAgent();
final ExperimentOutputManager manager = (ExperimentOutputManager) agent.getOutputManager();
Symbol layout = manager.getLayout();
if (layout == null) {
layout = manager;
}
final Boolean keepTabs = layout.getFacetValue(scope, "tabs", true);
final Boolean keepToolbars = layout.getFacetValue(scope, "toolbars", null);
final Boolean showParameters = layout.getFacetValue(scope, "parameters", null);
final Boolean showConsoles = layout.getFacetValue(scope, "consoles", null);
final Boolean showNavigator = layout.getFacetValue(scope, "navigator", null);
final Boolean showControls = layout.getFacetValue(scope, "controls", null);
final Boolean keepTray = layout.getFacetValue(scope, "tray", null);
boolean showEditors;
if (layout.hasFacet("editors")) {
showEditors = layout.getFacetValue(scope, "editors", false);
} else {
showEditors = !GamaPreferences.Modeling.EDITOR_PERSPECTIVE_HIDE.getValue();
}
WorkbenchHelper.runInUI("Arranging views", 0, (m) -> {
WorkbenchHelper.getPage().setEditorAreaVisible(showEditors);
if (showConsoles != null && !showConsoles) {
WorkbenchHelper.hideView(IGui.CONSOLE_VIEW_ID);
WorkbenchHelper.hideView(IGui.INTERACTIVE_CONSOLE_VIEW_ID);
} else {
getConsole().showConsoleView(exp.getAgent());
}
if (showParameters != null && !showParameters) {
WorkbenchHelper.hideView(IGui.PARAMETER_VIEW_ID);
} else {
updateParameterView(scope, exp);
}
if (showNavigator != null && !showNavigator) {
WorkbenchHelper.hideView(IGui.NAVIGATOR_VIEW_ID);
}
if (showControls != null) {
WorkbenchHelper.getWindow().setCoolBarVisible(showControls);
}
if (keepTray != null) {
PerspectiveHelper.showBottomTray(WorkbenchHelper.getWindow(), keepTray);
}
final SimulationPerspectiveDescriptor sd = PerspectiveHelper.getActiveSimulationPerspective();
if (sd != null) {
sd.keepTabs(keepTabs);
sd.keepToolbars(keepToolbars);
sd.keepControls(showControls);
sd.keepTray(keepTray);
}
});
}
}
/**
* Method cleanAfterExperiment()
*
* @see msi.gama.common.interfaces.IGui#cleanAfterExperiment(msi.gama.kernel.experiment.IExperimentPlan)
*/
@Override
public void cleanAfterExperiment() {
WorkbenchHelper.hideView(PARAMETER_VIEW_ID);
hideMonitorView();
getConsole().eraseConsole(true);
final IGamaView icv = (IGamaView) WorkbenchHelper.findView(INTERACTIVE_CONSOLE_VIEW_ID, null, false);
if (icv != null) {
icv.reset();
}
final IRuntimeExceptionHandler handler = getRuntimeExceptionHandler();
handler.stop();
}
private IRuntimeExceptionHandler getRuntimeExceptionHandler() {
return WorkbenchHelper.getService(IRuntimeExceptionHandler.class);
}
@Override
public void runModel(final Object object, final String exp) {
final IModelRunner modelRunner = getModelRunner();
if (modelRunner == null) { return; }
modelRunner.runModel(object, exp);
}
public static List<IDisplaySurface> allDisplaySurfaces() {
final List<IDisplaySurface> result = new ArrayList<>();
final IViewReference[] viewRefs = WorkbenchHelper.getPage().getViewReferences();
for (final IViewReference ref : viewRefs) {
final IWorkbenchPart part = ref.getPart(false);
if (part instanceof IGamaView.Display) {
result.add(((IGamaView.Display) part).getDisplaySurface());
}
}
return result;
}
/**
* Method updateSpeedDisplay()
*
* @see msi.gama.common.interfaces.IGui#updateSpeedDisplay(java.lang.Double)
*/
@Override
public void updateSpeedDisplay(final IScope scope, final Double d, final boolean notify) {
final ISpeedDisplayer speedStatus = WorkbenchHelper.getService(ISpeedDisplayer.class);
if (speedStatus != null) {
WorkbenchHelper.asyncRun(() -> speedStatus.setInit(d, notify));
}
}
/**
* Method getMetaDataProvider()
*
* @see msi.gama.common.interfaces.IGui#getMetaDataProvider()
*/
@Override
public IFileMetaDataProvider getMetaDataProvider() {
return WorkbenchHelper.getService(IFileMetaDataProvider.class);
}
@Override
public IGamlLabelProvider getGamlLabelProvider() {
return WorkbenchHelper.getService(IGamlLabelProvider.class);
}
@Override
public void closeSimulationViews(final IScope scope, final boolean openModelingPerspective,
final boolean immediately) {
WorkbenchHelper.run(() -> {
final IWorkbenchPage page = WorkbenchHelper.getPage();
final IViewReference[] views = page.getViewReferences();
for (final IViewReference view : views) {
final IViewPart part = view.getView(false);
if (part instanceof IGamaView) {
DEBUG.OUT("Closing " + view.getId());
((IGamaView) part).close(scope);
}
}
if (openModelingPerspective) {
DEBUG.OUT("Deleting simulation perspective and opening immediately the modeling perspective = "
+ immediately);
PerspectiveHelper.deleteCurrentSimulationPerspective();
PerspectiveHelper.openModelingPerspective(immediately, false);
}
getStatus(scope).neutralStatus("No simulation running");
});
}
@Override
public String getExperimentState(final String uid) {
final IExperimentController controller = GAMA.getFrontmostController();
if (controller == null) {
return NONE;
} else if (controller.getScheduler().paused) { return PAUSED; }
return RUNNING;
}
@Override
public void updateExperimentState(final IScope scope, final String forcedState) {
// DEBUG.OUT("STATE: " + forcedState);
final ISourceProviderService service = WorkbenchHelper.getService(ISourceProviderService.class);
final ISimulationStateProvider stateProvider = (ISimulationStateProvider) service
.getSourceProvider("ummisco.gama.ui.experiment.SimulationRunningState");
if (stateProvider != null) {
WorkbenchHelper.run(() -> stateProvider.updateStateTo(forcedState));
}
}
@Override
public void updateExperimentState(final IScope scope) {
updateExperimentState(scope, getExperimentState(""));
}
@Override
public void updateViewTitle(final IDisplayOutput out, final SimulationAgent agent) {
WorkbenchHelper.run(() -> {
final IViewPart part =
WorkbenchHelper.findView(out.getViewId(), out.isUnique() ? null : out.getName(), true);
if (part != null && part instanceof IGamaView) {
((IGamaView) part).changePartNameWithSimulation(agent);
}
});
}
@Override
public void updateDecorator(final String id) {
WorkbenchHelper.asyncRun(() -> WorkbenchHelper.getWorkbench().getDecoratorManager().update(id));
}
@Override
public IStatusDisplayer getStatus(final IScope scope) {
return WorkbenchHelper.getService(IStatusDisplayer.class);
}
@Override
public IConsoleDisplayer getConsole() {
return WorkbenchHelper.getService(IConsoleDisplayer.class);
}
@Override
public void run(final String taskName, final Runnable r, final boolean asynchronous) {
if (asynchronous) {
WorkbenchHelper.runInUI(taskName, 0, (m) -> r.run());
} else {
WorkbenchHelper.run(r);
}
}
@Override
public void setFocusOn(final IShape shape) {
for (final IDisplaySurface surface : this.allDisplaySurfaces()) {
surface.focusOn(shape);
}
GAMA.getExperiment().refreshAllOutputs();
}
@Override
public void applyLayout(final IScope scope, final Object layout) {
final IDisplayLayoutManager manager = WorkbenchHelper.getService(IDisplayLayoutManager.class);
if (manager != null) {
manager.applyLayout(layout);
}
}
@Override
public ILocation getMouseLocationInModel() {
return mouseLocationInModel;
}
@Override
public void setMouseLocationInModel(final ILocation location) {
mouseLocationInModel = location;
}
@Override
public void exit() {
WorkbenchHelper.asyncRun(() -> PlatformUI.getWorkbench().close());
}
@Override
public void openInteractiveConsole(final IScope scope) {
this.showView(scope, INTERACTIVE_CONSOLE_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
}
@Override
public boolean toggleFullScreenMode() {
final IViewPart part = WorkbenchHelper.findFrontmostGamaViewUnderMouse();
if (part instanceof IGamaView.Display) {
((IGamaView.Display) part).toggleFullScreen();
return true;
}
return false;
}
@Override
public void refreshNavigator() {
final IRefreshHandler refresh = WorkbenchHelper.getService(IRefreshHandler.class);
if (refresh != null) {
refresh.completeRefresh(null);
}
}
@Override
public boolean isInDisplayThread() {
return EventQueue.isDispatchThread() || Display.getCurrent() != null;
}
}