/
ApplicationActionBarAdvisor.java
965 lines (710 loc) · 29.3 KB
/
ApplicationActionBarAdvisor.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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
/*******************************************************************************
* Copyright (c) 2007-2012 M. Austenfeld
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* M. Austenfeld
*******************************************************************************/
package com.eco.bio7.rcp;
import java.io.File;
import java.io.FilenameFilter;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.registry.ActionSetRegistry;
import org.eclipse.ui.internal.registry.IActionSetDescriptor;
import org.eclipse.ui.views.IViewDescriptor;
import org.eclipse.ui.views.IViewRegistry;
import com.eco.bio7.Bio7Plugin;
import com.eco.bio7.actions.BeanShellClearAction;
import com.eco.bio7.actions.BeanShellImportAction;
import com.eco.bio7.actions.Compile;
import com.eco.bio7.actions.CounterReset;
import com.eco.bio7.actions.EnableSelection;
import com.eco.bio7.actions.ExecuteImageMacroAction;
import com.eco.bio7.actions.ExecuteScriptAction;
import com.eco.bio7.actions.FlowEditorAction;
import com.eco.bio7.actions.FlowEditorTestAction;
import com.eco.bio7.actions.FlowExternalStartAction;
import com.eco.bio7.actions.FlowStopAction;
import com.eco.bio7.actions.Interpret;
import com.eco.bio7.actions.InterpretPython;
import com.eco.bio7.actions.OfficeOpenAction;
import com.eco.bio7.actions.OfficeSendValueAction;
import com.eco.bio7.actions.OfficeValueAction;
import com.eco.bio7.actions.OpenBio7BrowserAction;
import com.eco.bio7.actions.OpenViewMenuAction;
import com.eco.bio7.actions.LibreOfficeConnection;
import com.eco.bio7.actions.Random;
import com.eco.bio7.actions.ResetField;
import com.eco.bio7.actions.SetupDiscrete;
import com.eco.bio7.actions.ShowEditorAreaAction;
import com.eco.bio7.actions.Start;
import com.eco.bio7.actions.Start3d;
import com.eco.bio7.popup.actions.KnitrAction;
import com.eco.bio7.popup.actions.RMarkdownAction;
import com.eco.bio7.preferences.PreferenceConstants;
import com.eco.bio7.rbridge.actions.ActivateRPlots;
import com.eco.bio7.rbridge.actions.ClearRWorkspace;
import com.eco.bio7.rbridge.actions.ClipboardRScipt;
import com.eco.bio7.rbridge.actions.ClipboardRValues;
import com.eco.bio7.rbridge.actions.ExecuteRScriptAction;
import com.eco.bio7.rbridge.actions.ExecuteRTextSelection;
import com.eco.bio7.rbridge.actions.InstallRPackage;
import com.eco.bio7.rbridge.actions.InterpretR;
import com.eco.bio7.rbridge.actions.LoadRLibrary;
import com.eco.bio7.rbridge.actions.LoadRWorkspace;
import com.eco.bio7.rbridge.actions.OfficeValueToRAction;
import com.eco.bio7.rbridge.actions.OfficeValueToRHeadAction;
import com.eco.bio7.rbridge.actions.OpenRservePreferencesAction;
import com.eco.bio7.rbridge.actions.PrintExpression;
import com.eco.bio7.rbridge.actions.SaveRWorkspace;
import com.eco.bio7.rbridge.actions.SaveRWorkspaceand_Start;
import com.eco.bio7.rbridge.actions.StartRServe;
import com.eco.bio7.scenebuilder.GenerateControllerAction;
import com.eco.bio7.time.Time;
import com.eco.bio7.util.Util;
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private static StatusLineContributionItem userItem = null;
private String id[] = new String[] { "org.eclipse.ui.views.ResourceNavigator", "org.eclipse.ui.console.ConsoleView", "com.eco.bio7.RShell", "com.eco.bio7.rbridge.RTable", "com.eco.bio7.imagej", "com.eco.bio7.ijtoolbar", "com.eco.bio7.image_methods", "com.eco.bio7.points","com.eco.bio7.image.TransferGeometryView",
"com.eco.bio7.browser.Browser", "com.eco.bio7.worldwind.WorldWindView", "com.eco.bio7.worldwind.WorldWindOptionsView", "com.eco.bio7.spatial", "com.eco.bio7.discrete3d.Options3d", "com.eco.bio7.control","com.eco.bio7.spreadsheet","com.eco.bio7.states","com.eco.bio7.quadgrid", "com.eco.bio7.hexgrid","com.eco.bio7.linechart","com.eco.bio7.piechart" };
private IWorkbenchWindow window;
private IWorkbenchAction exitAction;
private IWorkbenchAction print;
private IWorkbenchAction New;
private IWorkbenchAction saveall;
private IWorkbenchAction Import;
private IWorkbenchAction Export;
private IWorkbenchAction undo;
private IWorkbenchAction redo;
private IWorkbenchAction cut;
private IWorkbenchAction copy;
private IWorkbenchAction paste;
private IWorkbenchAction delete;
private IWorkbenchAction selectall;
private IWorkbenchAction find;
private IWorkbenchAction save;
private IWorkbenchAction saveas;
private IWorkbenchAction dynamichelp;
private IWorkbenchAction aboutAction;
private IWorkbenchAction newWindowAction;
private IWorkbenchAction introAction;
private static Action libreofficeconnection;
private static Action start;
private Action enableselection;
private IWorkbenchAction propAction;
private IWorkbenchAction helpAction;
private static Action start3d;
private Action resetfield;
private static Action counterreset;
private Action random;
private static Action startrserve;
private Action setup;
private static Action flowstop;
private IContributionItem viewShortlist;
private IContributionItem perspect;
private IWorkbenchWindow window2;
private IPreferenceStore store;
private OfficeOpenAction officeopenspread;
private OfficeValueToRAction officevaluetor;
private OfficeValueToRHeadAction officevaluetorhead;
private OfficeValueAction officevalue;
private OfficeSendValueAction officepopdata;
private static BeanShellImportAction bshimportaction;
private IWorkbenchAction saveperspectiveas;
private PrintExpression printexpression;
private static FlowExternalStartAction flowexternalstartaction;
private ExecuteRTextSelection rselect;
private ClipboardRScipt clipboardRScript;
private ClipboardRValues clipboardRValues;
private InstallRPackage installRPackage;
private LoadRLibrary loadRLibrary;
private OpenRservePreferencesAction openRservePref;
private LoadRWorkspace loadR;
private SaveRWorkspace saveR;
private OpenBio7BrowserAction openBrowser;
private MenuManager helpMenu;
private ActivateRPlots enableRPlots;
private InterpretR interpretR;
private Compile compileJava;
private FlowEditorAction flowAction;
private FlowEditorTestAction debugFlowAction;
private Interpret interpretGrovvyBeanShell;
private InterpretPython interpretPython;
private KnitrAction knitrAction;
private RMarkdownAction markdownAction;
private GenerateControllerAction generateControllerAction;
private ClearRWorkspace clearWorkspace;
private IContributionItem showViewItem;
//private IWorkbenchAction switchWorkspaceAction;
private IWorkbenchAction refreshAction;
public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
store = Bio7Plugin.getDefault().getPreferenceStore();
}
protected void makeActions(final IWorkbenchWindow window) {
window2 = window;
New = ActionFactory.NEW.create(window);
New.setText("New");
register(New);
officeopenspread = new OfficeOpenAction("Open Spreadsheet", window2);
officevaluetor = new OfficeValueToRAction("Data to R", window2);
officevaluetorhead = new OfficeValueToRHeadAction("Data with head to R ", window2);
officevalue = new OfficeValueAction("Data to Beanshell", window2);
officepopdata = new OfficeSendValueAction("Send Bio7 counts", window2);
save = ActionFactory.SAVE.create(window);
register(save);
saveall = ActionFactory.SAVE_ALL.create(window);
register(saveall);
saveas = ActionFactory.SAVE_AS.create(window);
register(saveas);
saveperspectiveas = ActionFactory.SAVE_PERSPECTIVE.create(window);
register(saveperspectiveas);
Import = ActionFactory.IMPORT.create(window);
register(Import);
Export = ActionFactory.EXPORT.create(window);
register(Export);
helpAction = ActionFactory.HELP_CONTENTS.create(window);
register(helpAction);
/*
* findAction = ActionFactory.FIND.create(window); register(findAction);
*/
print = ActionFactory.PRINT.create(window);
register(print);
find = ActionFactory.FIND.create(window);
register(find);
cut = ActionFactory.CUT.create(window);
register(cut);
copy = ActionFactory.COPY.create(window);
register(copy);
delete = ActionFactory.DELETE.create(window);
register(delete);
paste = ActionFactory.PASTE.create(window);
register(paste);
selectall = ActionFactory.SELECT_ALL.create(window);
register(selectall);
undo = ActionFactory.UNDO.create(window);
register(undo);
redo = ActionFactory.REDO.create(window);
register(redo);
dynamichelp = ActionFactory.DYNAMIC_HELP.create(window);
register(dynamichelp);
introAction = ActionFactory.INTRO.create(window);
register(introAction);
propAction = ActionFactory.PREFERENCES.create(window);
register(propAction);
/* Avoid buggy action on MacOSX */
if (!Util.getOS().equals("Mac")) {
exitAction = ActionFactory.QUIT.create(window);
register(exitAction);
}
aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(window);
register(newWindowAction);
showViewItem = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
libreofficeconnection = new LibreOfficeConnection("Open LibreOffice Connection", window);
register(libreofficeconnection);
start = new Start("Start", window);
register(start);
start3d = new Start3d("Start/Stop Animation", window);
register(start3d);
resetfield = new ResetField("Reset Field", window);
register(resetfield);
counterreset = new CounterReset("Counter Reset", window);
register(counterreset);
enableselection = new EnableSelection("EnableSelection", window);
register(enableselection);
random = new Random("Random", window);
register(random);
startrserve = new StartRServe("Start Rserve", window);
register(startrserve);
printexpression = new PrintExpression("PrintExpression", window);
register(printexpression);
setup = new SetupDiscrete("Save Pattern", window);
register(setup);
viewShortlist = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
perspect = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
flowexternalstartaction = new FlowExternalStartAction("Flowexternalstart", window);
register(flowexternalstartaction);
flowstop = new FlowStopAction("Flowstop", window);
register(flowstop);
rselect = new ExecuteRTextSelection("Evaluate Selection", window);
register(rselect);
clipboardRScript = new ClipboardRScipt("Evaluate Clipboard", window);
register(clipboardRScript);
clipboardRValues = new ClipboardRValues("Get Clipboard Data", window);
register(clipboardRValues);
enableRPlots = new ActivateRPlots("Activate R Plots", window);
register(enableRPlots);
installRPackage = new InstallRPackage("Install package(s)", window);
register(installRPackage);
loadRLibrary = new LoadRLibrary("Load/Remove package(s)", window);
register(loadRLibrary);
openRservePref = new OpenRservePreferencesAction();
register(openRservePref);
loadR = new LoadRWorkspace("Load Workspace", window);
register(loadR);
saveR = new SaveRWorkspace("Save Workspace", window);
register(saveR);
clearWorkspace=new ClearRWorkspace("Remove all objects", window);
register(clearWorkspace);
openBrowser = new OpenBio7BrowserAction("Bio7 Internet", window);
register(openBrowser);
interpretR = new InterpretR("Interpret R", window);
register(interpretR);
compileJava = new Compile("Compile Java");
register(compileJava);
flowAction = new FlowEditorAction("Execute Flow");
register(flowAction);
debugFlowAction = new FlowEditorTestAction("Debug Flow");
register(debugFlowAction);
interpretGrovvyBeanShell = new Interpret("Interpret Groovy/BeanShell");
register(interpretGrovvyBeanShell);
interpretPython = new InterpretPython("Interpret Python");
register(interpretPython);
knitrAction = new KnitrAction();
register(knitrAction);
markdownAction = new RMarkdownAction();
register(markdownAction);
generateControllerAction = new GenerateControllerAction("Generate Controller Class");
register(generateControllerAction);
/*switchWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE.create(window);
register(switchWorkspaceAction);*/
refreshAction = ActionFactory.REFRESH.create(window);
register(refreshAction);
}
protected void fillMenuBar(IMenuManager menuBar) {
/*
* Remove actions tip from:
* http://random-eclipse-tips.blogspot.de/2009/02
* /eclipse-rcp-removing-unwanted_02.html
*/
// SHOW_JDT_GUI
IPreferenceStore store = Bio7Plugin.getDefault().getPreferenceStore();
boolean showJDTGui = store.getBoolean("SHOW_JDT_GUI");
if (showJDTGui == false) {
final ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();
final IActionSetDescriptor[] actionSets = reg.getActionSets();
final String[] removeActionSets = new String[] { "org.eclipse.search.searchActionSet", "org.eclipse.ui.cheatsheets.actionSet", "org.eclipse.ui.actionSet.keyBindings", "org.eclipse.ui.edit.text.actionSet.navigation", "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
"org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo", "org.eclipse.ui.edit.text.actionSet.openExternalFile", "org.eclipse.ui.externaltools.ExternalToolsSet", "org.eclipse.ui.externaltools.ExternalToolsSet", "org.eclipse.ui.WorkingSetActionSet",
"org.eclipse.update.ui.softwareUpdates", "org.eclipse.ui.actionSet.openFiles", "org.eclipse.mylyn.tasks.ui.navigation", "org.eclipse.debug.ui.launchActionSet", "org.eclipse.jdt.ui.JavaElementCreationActionSet", "org.eclipse.jdt.ui.JavaActionSet",
"org.eclipse.ui.edit.text.actionSet.presentation", "org.eclipse.ui.cheatsheets.actionSet", "org.eclipse.ui.externaltools.ExternalToolsSet", "org.eclipse.jdt.ui.text.java.actionSet.presentation", "org.eclipse.debug.ui.breakpointActionSet", "org.eclipse.wb.core.ui.actionset" };
for (int i = 0; i < actionSets.length; i++) {
boolean found = false;
for (int j = 0; j < removeActionSets.length; j++) {
if (removeActionSets[j].equals(actionSets[i].getId())) {
found = true;
}
}
if (!found) {
continue;
}
final IExtension ext = actionSets[i].getConfigurationElement().getDeclaringExtension();
reg.removeExtension(ext, new Object[] { actionSets[i] });
}
}
MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
editMenu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT)); // should
// resolve
// it
MenuManager findMenu = new MenuManager("&Search", IWorkbenchActionConstants.FIND_EXT);
findMenu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT)); // should
// resolve
// it
MenuManager prefMenu = new MenuManager("Preferences");
/* Set not an references extra menu for MacOSX! */
prefMenu.setVisible(!Util.getOS().equals("Mac"));
MenuManager rMenu = new MenuManager("R");
MenuManager OpenOfficeMenu = new MenuManager("LibreOffice");
// MenuManager BeanShellMenu = new MenuManager("Bsh");
MenuManager WindowMenu = new MenuManager("&Window");
helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);// p2
MenuManager showViewMenuMgr = new MenuManager("Show View", "showView");
//MenuManager showViewMenu = new MenuManager("Show View");
MenuManager openPerspectiveMenu = new MenuManager("Open Perspective");
MenuManager scriptMenu = new MenuManager("&Scripts");
//
MenuManager generalMenu = new MenuManager("&General-Scripts");
generalMenu.add(new ExecuteScriptAction("Empty", window2, new File("")));
generalMenu.setRemoveAllWhenShown(true);
IMenuListener listener = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
File files = new File(store.getString(PreferenceConstants.D_SCRIPT_GENERAL));
File[] fil = new Util().ListFilesDirectory(files, new String[] { ".java", ".bsh", ".groovy", ".py" });
if (fil.length > 0) {
int a;
for (int i = 0; i < fil.length; i++) {
m.add(new ExecuteScriptAction(fil[i].getName().substring(0, fil[i].getName().lastIndexOf(".")), window2, fil[i]));
a = i + 1;
if (a % 5 == 0) {
m.add(new Separator());
}
}
}
else {
m.add(new ExecuteScriptAction("Empty", window2, new File("")));
}
}
};
generalMenu.addMenuListener(listener);
MenuManager spatialMenu = new MenuManager("&Spatial-Scripts");
spatialMenu.add(new ExecuteScriptAction("Empty", window2, new File("")));
spatialMenu.setRemoveAllWhenShown(true);
IMenuListener listener4 = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
File files = new File(store.getString(PreferenceConstants.D_SCRIPT_SPATIAL));
File[] fil = new Util().ListFilesDirectory(files, new String[] { ".java", ".bsh", ".groovy", ".py" });
if (fil.length > 0) {
int a;
for (int i = 0; i < fil.length; i++) {
m.add(new ExecuteScriptAction(fil[i].getName().substring(0, fil[i].getName().lastIndexOf(".")), window2, fil[i]));
a = i + 1;
if (a % 5 == 0) {
m.add(new Separator());
}
}
}
else {
m.add(new ExecuteScriptAction("Empty", window2, new File("")));
}
}
};
spatialMenu.addMenuListener(listener4);
MenuManager macrosImageJMenu = new MenuManager("&ImageJ-Macros");
macrosImageJMenu.add(new ExecuteImageMacroAction("Empty", window2, new File("")));
macrosImageJMenu.setRemoveAllWhenShown(true);
IMenuListener listener5 = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
File files = new File(store.getString(PreferenceConstants.D_SCRIPT_IMAGE));
File[] fil = new Util().ListFileDirectory(files, ".txt");
if (fil.length > 0) {
int a;
for (int i = 0; i < fil.length; i++) {
m.add(new ExecuteImageMacroAction(fil[i].getName().substring(0, fil[i].getName().lastIndexOf(".")), window2, fil[i]));
a = i + 1;
if (a % 5 == 0) {
m.add(new Separator());
}
}
}
else {
m.add(new ExecuteImageMacroAction("Empty", window2, new File("")));
}
}
};
macrosImageJMenu.addMenuListener(listener5);
MenuManager rScriptMenu = new MenuManager("&R-Scripts");
rScriptMenu.add(new ExecuteScriptAction("Empty", window2, new File("")));
rScriptMenu.setRemoveAllWhenShown(true);
IMenuListener listener6 = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
File files = new File(store.getString(PreferenceConstants.D_SCRIPT_R));
File[] fil = new Util().ListFileDirectory(files, ".R");
if (fil.length > 0) {
int a;
for (int i = 0; i < fil.length; i++) {
m.add(new ExecuteRScriptAction(fil[i].getName().substring(0, fil[i].getName().lastIndexOf(".")), window2, fil[i]));
a = i + 1;
if (a % 5 == 0) {
m.add(new Separator());
}
}
}
else {
m.add(new ExecuteScriptAction("Empty", window2, new File("")));
}
}
};
rScriptMenu.addMenuListener(listener6);
MenuManager importScriptMenu = new MenuManager("&Import-Scripts");
importScriptMenu.add(new ExecuteScriptAction("Empty", window2, new File("")));
importScriptMenu.setRemoveAllWhenShown(true);
IMenuListener listener2 = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
File files = new File(store.getString(PreferenceConstants.D_IMPORT));
File[] fil = new Util().ListFilesDirectory(files, new String[] { ".java", ".bsh", ".groovy", ".py" });
if (fil.length > 0) {
int a;
for (int i = 0; i < fil.length; i++) {
m.add(new ExecuteScriptAction(fil[i].getName().substring(0, fil[i].getName().lastIndexOf(".")), window2, fil[i]));
a = i + 1;
if (a % 5 == 0) {
m.add(new Separator());
}
}
}
else {
m.add(new ExecuteScriptAction("Empty", window2, new File("")));
}
}
};
importScriptMenu.addMenuListener(listener2);
MenuManager exportScriptMenu = new MenuManager("&Export-Scripts");
exportScriptMenu.add(new ExecuteScriptAction("Empty", window2, new File("")));
exportScriptMenu.setRemoveAllWhenShown(true);
IMenuListener listener3 = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
File files = new File(store.getString(PreferenceConstants.D_EXPORT));
File[] fil = new Util().ListFilesDirectory(files, new String[] { ".java", ".bsh", ".groovy", ".py" });
if (fil.length > 0) {
int a;
for (int i = 0; i < fil.length; i++) {
m.add(new ExecuteScriptAction(fil[i].getName().substring(0, fil[i].getName().lastIndexOf(".")), window2, fil[i]));
a = i + 1;
if (a % 5 == 0) {
m.add(new Separator());
}
}
}
else {
m.add(new ExecuteScriptAction("Empty", window2, new File("")));
}
}
};
exportScriptMenu.addMenuListener(listener3);
/* Implement a custom show view action! */
MenuManager viewMenu = new MenuManager("&Show Selected View");
viewMenu.add(new ExecuteScriptAction("Empty", window2, new File("")));
viewMenu.setRemoveAllWhenShown(true);
IMenuListener listenerView = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
IViewRegistry viewRegistry = PlatformUI.getWorkbench().getViewRegistry();
IViewDescriptor[] views = viewRegistry.getViews();
for (int i = 0; i < id.length; i++) {
if (i==2||i==4||i==9||i==10||i==12||i==14) {
viewMenu.add(new Separator());
}
for (int j = 0; j < views.length; j++) {
if (id[i].equals(views[j].getId()))
viewMenu.add(new OpenViewMenuAction(views[j].getLabel(), views[j].getId()));
}
}
}
};
viewMenu.addMenuListener(listenerView);
// showViewMenu.add(re);
/* Implement a custom show view action! */
MenuManager viewMenuAll = new MenuManager("&Show All Views (Unordered)");
viewMenuAll.add(new ExecuteScriptAction("Empty", window2, new File("")));
viewMenuAll.setRemoveAllWhenShown(true);
IMenuListener listenerViewAll = new IMenuListener() {
public void menuAboutToShow(IMenuManager m) {
IViewRegistry viewRegistry = PlatformUI.getWorkbench().getViewRegistry();
IViewDescriptor[] views = viewRegistry.getViews();
for (IViewDescriptor iViewDescriptor : views) {
viewMenuAll.add(new OpenViewMenuAction(iViewDescriptor.getLabel(), iViewDescriptor.getId()));
}
}
};
viewMenuAll.addMenuListener(listenerViewAll);
// showViewMenu.add(re);
openPerspectiveMenu.add(perspect);
prefMenu.add(propAction);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(findMenu);
menuBar.add(prefMenu);
menuBar.add(scriptMenu);
menuBar.add(rMenu);
menuBar.add(OpenOfficeMenu);
// menuBar.add(BeanShellMenu);
menuBar.add(WindowMenu);
menuBar.add(helpMenu);
// Add a group marker indicating where action set menus will appear.
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
fileMenu.add(New);
fileMenu.add(new Separator());
// fileMenu.add(loadpattern);
// fileMenu.add(savepattern);
fileMenu.add(new Separator());
fileMenu.add(importScriptMenu);
fileMenu.add(exportScriptMenu);
fileMenu.add(new Separator());
fileMenu.add(new Separator());
fileMenu.add(save);
fileMenu.add(saveall);
fileMenu.add(saveas);
fileMenu.add(refreshAction);
//fileMenu.add(switchWorkspaceAction);
fileMenu.add(new Separator());
fileMenu.add(Import);
fileMenu.add(Export);
fileMenu.add(new Separator());
/* Avoid buggy action on MacOSX */
if (!Util.getOS().equals("Mac")) {
fileMenu.add(exitAction);
}
editMenu.add(undo);
editMenu.add(redo);
editMenu.add(new Separator());
editMenu.add(cut);
editMenu.add(copy);
editMenu.add(paste);
editMenu.add(new Separator());
editMenu.add(delete);
editMenu.add(new Separator());
editMenu.add(find);
editMenu.add(new Separator());
editMenu.add(selectall);
editMenu.add(new Separator());
editMenu.add(print);
// findMenu.add(findAction);
scriptMenu.add(generalMenu);
scriptMenu.add(new Separator());
scriptMenu.add(rScriptMenu);
scriptMenu.add(new Separator());
scriptMenu.add(spatialMenu);
scriptMenu.add(new Separator());
scriptMenu.add(macrosImageJMenu);
rMenu.add(startrserve);
rMenu.add(new Separator());
rMenu.add(loadR);
rMenu.add(saveR);
rMenu.add(new Separator());
rMenu.add(new PrintExpression("Evaluate Expression", window2));
rMenu.add(rselect);
rMenu.add(clipboardRScript);
rMenu.add(new Separator());
rMenu.add(clipboardRValues);
rMenu.add(new Separator());
rMenu.add(clearWorkspace);
rMenu.add(new Separator());
rMenu.add(installRPackage);
rMenu.add(loadRLibrary);
rMenu.add(new Separator());
if (ApplicationWorkbenchWindowAdvisor.getOS().equals("Windows")) {
rMenu.add(new SaveRWorkspaceand_Start("Start RGui with Workspace", window2));
} else {
//No R shell for Bio7 Linux and Mac.
//rMenu.add(new SaveRWorkspaceand_Start("Start R Shell", window2));
}
rMenu.add(new Separator());
rMenu.add(openRservePref);
OpenOfficeMenu.add(officeopenspread);
OpenOfficeMenu.add(new Separator());
OpenOfficeMenu.add(officevaluetor);
OpenOfficeMenu.add(officevaluetorhead);
OpenOfficeMenu.add(officevalue);
OpenOfficeMenu.add(new Separator());
OpenOfficeMenu.add(officepopdata);
/*
* BeanShellMenu.add(bshclearaction); BeanShellMenu.add(new
* Separator()); BeanShellMenu.add(bshimportaction);
*/
WindowMenu.add(viewMenu);
WindowMenu.add(viewMenuAll);
showViewMenuMgr.add(showViewItem);
WindowMenu.add(showViewMenuMgr);
//WindowMenu.add(showViewMenu); // Displays the show menu.
WindowMenu.add(openPerspectiveMenu);
WindowMenu.add(new Separator());
WindowMenu.add(new ShowEditorAreaAction("Show/Hide Editor", window2));
WindowMenu.add(new Separator());
WindowMenu.add(saveperspectiveas);
helpMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
if (ApplicationWorkbenchWindowAdvisor.getOS().equals("Windows")) {
helpMenu.add(introAction);
}
helpMenu.add(new Separator());
helpMenu.add(helpAction);
helpMenu.add(dynamichelp);
helpMenu.add(new Separator());
helpMenu.add(openBrowser);
helpMenu.add(new Separator());
// helpMenu.add(update_action);
// helpMenu.add(add_extension);
helpMenu.add(new Separator());
helpMenu.add(aboutAction);
}
public void fillStatusLine(IStatusLineManager statusLineMgr) {
super.fillStatusLine(statusLineMgr);
userItem = new StatusLineContributionItem("Timesteps");
userItem.setText("Timesteps: " + Time.getCounter());
statusLineMgr.add(userItem);
}
protected void fillCoolBar(ICoolBarManager coolBar) {
IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.LEFT);
// IToolBarManager imagebar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
// coolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
coolBar.add(new ToolBarContributionItem(toolbar, "mainbio7"));
// coolBar.add(new ToolBarContributionItem(imagebar, "image"));
toolbar.add(start);
toolbar.add(setup);
toolbar.add(resetfield);
toolbar.add(counterreset);
toolbar.add(random);
toolbar.add(libreofficeconnection);
toolbar.add(startrserve);
toolbar.add(print);
}
public static Action getStart() {
return start;
}
public static Action getStartrserve() {
return startrserve;
}
public static Action getOpenofficeconnection() {
return libreofficeconnection;
}
public static Action getFlowstop() {
return flowstop;
}
public static FlowExternalStartAction getFlowexternalstartaction() {
return flowexternalstartaction;
}
public static BeanShellImportAction getBshimportaction() {
return bshimportaction;
}
public static Action getCounterreset() {
return counterreset;
}
public static Action getStart3d() {
return start3d;
}
public static StatusLineContributionItem getUserItem() {
return userItem;
}
protected MenuManager createSubMenu(String text, String id, ContributionItemFactory factory) {
MenuManager submenu = new MenuManager(text, id);
submenu.add(factory.create(this.window));
return submenu;
}
protected MenuManager createSubMenu(String text, String id, Object... items) {
MenuManager submenu = new MenuManager(text, id);
for (Object i : items) {
if (i instanceof IContributionItem)
submenu.add((IContributionItem) i);
else if (i instanceof IWorkbenchAction)
submenu.add((IWorkbenchAction) i);
}
return submenu;
}
}