This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ICEFormEditor.java
1325 lines (1108 loc) · 36.8 KB
/
ICEFormEditor.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
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2014- UT-Battelle, LLC.
* 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:
* Initial API and implementation and/or initial documentation - Jay Jay Billings,
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.client.widgets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ice.client.common.TreeCompositeViewer;
import org.eclipse.ice.client.widgets.viz.service.IVizServiceFactory;
import org.eclipse.ice.datastructures.ICEObject.Component;
import org.eclipse.ice.datastructures.ICEObject.ICEObject;
import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.datastructures.ICEObject.ListComponent;
import org.eclipse.ice.datastructures.componentVisitor.IComponentVisitor;
import org.eclipse.ice.datastructures.componentVisitor.IReactorComponent;
import org.eclipse.ice.datastructures.form.AdaptiveTreeComposite;
import org.eclipse.ice.datastructures.form.DataComponent;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.form.MasterDetailsComponent;
import org.eclipse.ice.datastructures.form.MatrixComponent;
import org.eclipse.ice.datastructures.form.ResourceComponent;
import org.eclipse.ice.datastructures.form.TableComponent;
import org.eclipse.ice.datastructures.form.TimeDataComponent;
import org.eclipse.ice.datastructures.form.TreeComposite;
import org.eclipse.ice.datastructures.form.emf.EMFComponent;
import org.eclipse.ice.datastructures.form.geometry.GeometryComponent;
import org.eclipse.ice.datastructures.form.geometry.IShape;
import org.eclipse.ice.datastructures.form.mesh.MeshComponent;
import org.eclipse.ice.iclient.uiwidgets.IObservableWidget;
import org.eclipse.ice.iclient.uiwidgets.IProcessEventListener;
import org.eclipse.ice.iclient.uiwidgets.ISimpleResourceProvider;
import org.eclipse.ice.iclient.uiwidgets.IUpdateEventListener;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.IMessageManager;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.editor.SharedHeaderFormEditor;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* The ICEFormEditor is an Eclipse FormEditor subclass that renders and displays
* a Form. It is also observable, as described by the IObservableWidget
* interface, and it dispatches updates to IUpdateEventListeners and
* IProcessEventListeners.
*
* @author Jay Jay Billings
*/
public class ICEFormEditor extends SharedHeaderFormEditor implements
IComponentVisitor, IObservableWidget, IUpdateableListener {
/**
* ID for Eclipse
*/
public static final String ID = "org.eclipse.ice.client.widgets.ICEFormEditor";
/**
* The component handle for the visualization service factory.
*/
private static IVizServiceFactory vizFactory;
/**
* Dirty state for Eclipse
*/
private boolean dirty = false;
/**
* The Component Map. This map is used to organize the Components in the
* Form by type. The type is the key and is a string equal to one of "data,"
* "output," "matrix," "masterDetails", "table," "geometry," "shape" or
* "tree," or reactor. The value is a list that stores all components of
* that type. This is a simulated multimap.
*/
protected HashMap<String, ArrayList<Component>> componentMap = new HashMap<String, ArrayList<Component>>();
private ICEFormInput ICEFormInput;
/**
* The form for this FormEditor retrieved from the ICEFormInput.
*/
protected Form iceDataForm;
/**
* The name of the action that should be performed when the Form is
* processed.
*/
protected String processName;
/**
* The SWT drop-down menu used in action processing.
*/
protected Combo processDropDown;
/**
* The SWT button used in action processing.
*/
protected Button goButton;
/**
* The SWT button used to cancel a process request.
*/
protected Button cancelButton;
/**
* The list of IProcessEventListeners that have subscribed to the parent ICE
* UIWidget of this Eclipse Editor.
*/
private ArrayList<IProcessEventListener> processListeners;
/**
* The list of IUpdateEventListeners that have subscribed to the parent ICE
* UIWidget of this Eclipse Editor.
*/
private ArrayList<IUpdateEventListener> updateListeners;
/**
* The ISimpleResourceProvider that should be used to load ICEResources for
* the user.
*/
private ISimpleResourceProvider resourceProvider;
/**
* The ICEResourcePage associated to this form editor.
*/
protected ICEResourcePage resourceComponentPage;
/**
* This class' ICEFormPage that displays the GeometryEditor powered by JME3.
*/
protected ICEGeometryPage geometryPage;
/**
* This class' ICEFormPage that displays the MeshEditor powered by JME3.
*/
protected ICEMeshPage meshPage;
/**
* The Constructor
*/
public ICEFormEditor() {
// Setup listener lists
updateListeners = new ArrayList<IUpdateEventListener>();
processListeners = new ArrayList<IProcessEventListener>();
// Setup the component map
componentMap.put("data", new ArrayList<Component>());
componentMap.put("output", new ArrayList<Component>());
componentMap.put("table", new ArrayList<Component>());
componentMap.put("matrix", new ArrayList<Component>());
componentMap.put("masterDetails", new ArrayList<Component>());
componentMap.put("shape", new ArrayList<Component>());
componentMap.put("geometry", new ArrayList<Component>());
componentMap.put("mesh", new ArrayList<Component>());
componentMap.put("tree", new ArrayList<Component>());
componentMap.put("reactor", new ArrayList<Component>());
componentMap.put("emf", new ArrayList<Component>());
componentMap.put("list", new ArrayList<Component>());
}
/**
* This is a static operation to set the IVizServiceFactory component
* reference for the FormEditor.
*
* @param factory
* The service factory that should be used for generating
* visualizations.
*/
public static void setVizServiceFactory(IVizServiceFactory factory) {
vizFactory = factory;
System.out.println("ICEFormEditor Message: IVizServiceFactory set!");
}
/**
* This gets the current IVizServiceFactory component for use in the
* FormEditor.
*
* @return The {@link #vizFactory}.
*/
protected IVizServiceFactory getVizServiceFactory() {
return vizFactory;
}
/**
* This operation changes the dirty state of the FormEditor.
*
* @param value
*/
public void setDirty(boolean value) {
// Set the dirty value and fire a property change
dirty = value;
firePropertyChange(PROP_DIRTY);
}
/**
* This operation sets the focus to this editor and also updates the
* TreeCompositeViewer, if required.
*/
@Override
public void setFocus() {
// Call the super class' version of this because we definitely want
// whatever it does.
super.setFocus();
return;
}
/**
* This operation adds a Component to the map with the specified key. It is
* called by the visit() operations.
*
* @param component
* The Component to insert into the map of Components.
* @param tag
* The tag that identifies the type of the Component, equal to
* one of "unspecified" or "output."
*/
private void addComponentToMap(Component component, String tag) {
// Local Declarations
ArrayList<Component> components = null;
// Add the DataComponent to the map
if (component != null) {
// Grab the list of DataComponents
components = this.componentMap.get(tag);
// Add the Component
components.add(component);
}
return;
}
/**
* This operation creates the ICEResourcePage that will show any output
* files created by ICE.
*
* @return The ICEResourcePage that should be rendered as part of the Form.
*/
private ICEFormPage createResourcePage() {
// Local Declarations
ResourceComponent resourceComponent = null;
// Get the ResourceComponent and create the ICEOutput page. There
// should
// only be one output page.
if (!(componentMap.get("output").isEmpty())) {
resourceComponent = (ResourceComponent) (componentMap.get("output")
.get(0));
if (resourceComponent != null) {
// Make the page
resourceComponentPage = new ICEResourcePage(this,
resourceComponent.getName(),
resourceComponent.getName());
// Set the ResourceComponent
resourceComponentPage.setVizService(vizFactory);
resourceComponentPage.setResourceComponent(resourceComponent);
}
}
return resourceComponentPage;
}
/**
* This method returns the ICEResourcePage that this ICEFormEditor manages.
*
* @return The ICEResourcePage.
*/
public ICEResourcePage getResourcePage() {
return this.resourceComponentPage;
}
/**
* This operation creates an ICEMasterDetailsPage which will show data in a
* form consistent with the master-details pattern. It uses
* MasterDetailsComponents from ICE.
*
* @return The Form pages, one for each MasterDetailsComponent.
*/
private ArrayList<ICEFormPage> createMasterDetailsComponentPages() {
// Local Declarations
ArrayList<ICEFormPage> masterDetailsPages = new ArrayList<ICEFormPage>();
MasterDetailsComponent masterDetailsComponent = null;
// Get the MasterDetailsComponent and create the MasterDetails page.
if (!(componentMap.get("masterDetails").isEmpty())) {
masterDetailsComponent = (MasterDetailsComponent) (componentMap
.get("masterDetails").get(0));
if (masterDetailsComponent != null) {
// Get the name
String name = masterDetailsComponent.getName();
// Make the page
ICEMasterDetailsPage iCEMasterDetailsPage = new ICEMasterDetailsPage(
this, "MDPid", name);
// Set the MasterDetailsComponent
iCEMasterDetailsPage
.setMasterDetailsComponent(masterDetailsComponent);
masterDetailsPages.add(iCEMasterDetailsPage);
}
}
return masterDetailsPages;
}
/**
* This operation posts a status message to the ICEFormEditor should be
* displayed to the user or system viewing the widget. It is a simple
* string.
*
* @param statusMessage
* The status message.
*/
public void updateStatus(String statusMessage) {
// Local Declarations
final String message = statusMessage;
// Sync with the display
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
// Post the message to the update manager
if (getHeaderForm() != null) {
final IMessageManager messageManager = getHeaderForm()
.getMessageManager();
messageManager.addMessage("statusUpdate", message, null,
IMessageProvider.INFORMATION);
}
}
});
}
/**
* Creates a GeometryPage to display shapes powered with JME3. Also gives
* the geometryComponent to provide data to display.
*
* @return The GeometryPage created.
*/
private ICEFormPage createGeometryPage() {
// Local Declarations
GeometryComponent geometryComponent = new GeometryComponent();
// Get the GeometryComponent and create the GeometryPage.
if (!(componentMap.get("geometry").isEmpty())) {
geometryComponent = (GeometryComponent) (componentMap
.get("geometry").get(0));
if (geometryComponent != null) {
// Make the GeometryPage
geometryPage = new ICEGeometryPage(this, "GPid",
geometryComponent.getName());
// Set the GeometryComponent
geometryPage.setGeometry(geometryComponent);
}
}
return geometryPage;
}
/**
* Creates a MeshPage to display 2D meshes powered with JME3. Also gives the
* MeshComponent to provide data to display.
*
* @return The MeshPage created.
*/
private ICEFormPage createMeshPage() {
// Local Declarations
MeshComponent meshComponent = new MeshComponent();
// Get the GeometryComponent and create the GeometryPage.
if (!(componentMap.get("mesh").isEmpty())) {
meshComponent = (MeshComponent) (componentMap.get("mesh").get(0));
if (meshComponent != null) {
// Make the MeshPage
meshPage = new ICEMeshPage(this, "MeshPid",
meshComponent.getName());
// Set the MeshComponent
meshPage.setMeshComponent(meshComponent);
}
}
return meshPage;
}
/**
* This operation creates a list of ICEFormPages for EMFComponents.
*
* @return The ICEFormPages for each EMF Component in the list.
*/
private ArrayList<ICEFormPage> createEMFSectionPages() {
// Local Declarations
EMFComponent emfComponent = null;
EMFSectionPage emfPage = null;
ArrayList<ICEFormPage> pages = new ArrayList<ICEFormPage>();
// Get the EMFComponent and create the EMFSectionPage.
if (componentMap.get("emf").size() > 0) {
for (Component comp : componentMap.get("emf")) {
emfComponent = (EMFComponent) comp;
if (emfComponent != null) {
// Make the EMFSectionPage
emfPage = new EMFSectionPage(this, emfComponent.getName(),
emfComponent.getName());
// Set the EMFComponent
emfPage.setEMFComponent(emfComponent);
pages.add(emfPage);
}
}
}
return pages;
}
/**
* This operation creates a set of ICEFormPages for ListComponents that are
* stored in the component map.
*
* @return The pages.
*/
private ArrayList<ICEFormPage> createListSectionPages() {
// Create the list of pages to return
ArrayList<ICEFormPage> pages = new ArrayList<ICEFormPage>();
// Get the lists from the component map
ArrayList<Component> lists = componentMap.get("list");
// If there are some lists, render sections for them
if (lists.size() > 0) {
for (int i = 0; i < lists.size(); i++) {
ListComponent<?> list = (ListComponent<?>) lists.get(i);
// Make sure the list isn't null since that value can be put in
// a collection
if (list != null) {
// Create a new page for the list
ListComponentSectionPage page = new ListComponentSectionPage(
this, list.getName(), list.getName());
page.setList(list);
// Add the page to the return list
pages.add(page);
}
}
}
return pages;
}
/**
* This operation sets the input on the TreeCompositeViewer to the
* TreeComposite or set of TreeComposites in ICE.
*/
private void setTreeCompositeViewerInput() {
// Only go through the trouble if there is a TreeComposite to be had
List<Component> trees = componentMap.get("tree");
if (!trees.isEmpty()) {
// Show the view
try {
getSite().getWorkbenchWindow().getActivePage()
.showView(getTreeCompositeViewerID());
} catch (PartInitException e) {
e.printStackTrace();
}
// Get the TreeComposite to pass to the tree view.
int id = getTreeCompositeViewerInputID();
TreeComposite tree = null;
if (id != -1) {
// If the ID is specified, find the matching tree.
for (Component formTree : trees) {
if (id == formTree.getId()) {
tree = (TreeComposite) formTree;
break;
}
}
}
// If no tree was found, get the first available one.
if (tree == null) {
tree = (TreeComposite) trees.get(0);
}
// Get the TreeCompositeViewer
TreeCompositeViewer treeView = (TreeCompositeViewer) getSite()
.getWorkbenchWindow().getActivePage()
.findView(getTreeCompositeViewerID());
// Set the tree as input to the tree view
treeView.setInput(tree, this);
// Register the FormEditor to receive updates from the TreeComposite
// and its children because they are being edited externally but
// should still trigger a save event.
// FIXME We should not register with the TreeComposite more than
// once. However, the register and unregister calls are heavyweight
// (recursive). We should use some other logic to ensure
// registration doesn't happen more than once for the current
// TreeComposite.
tree.unregister(this);
tree.register(this);
}
}
/**
* This operation retrieves the ID of the TreeCompositeViewer to be used.
* Subclasses should override this method to return their own ID.
*
* @return The String ID of the TreeCompositeViewer
*/
protected String getTreeCompositeViewerID() {
return TreeCompositeViewer.ID;
}
/**
* This operation retrieves the ID of the TreeComposite that is passed as
* input to the TreeCompositeViewer.
*
* @return The integer ID of the TreeComposite to show in the
* TreeCompositeViewer.
*/
protected int getTreeCompositeViewerInputID() {
return -1;
}
/**
* This operation disables the ICEFormEditor. Disabled ICEFormEditors will
* not make it possible for clients to process the Form.
*
* @param state
* True if the editor is disabled, false if not.
*/
public void disable(boolean state) {
// Local Declarations
final boolean buttonState = state;
// Sync with the display
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
// Disable processing. Enabled = !disabled
goButton.setEnabled(!buttonState);
}
});
}
/**
* This operation overrides the createHeaderContents operations from the
* SharedHeaderFormEditor super class to create a common header across the
* top of the Form pages.
*
* @param headerForm
* The IManagedForm that manages the content in the common
* header.
*/
protected void createHeaderContents(IManagedForm headerForm) {
// Get the Form that provides the common header and decorate it.
org.eclipse.ui.forms.widgets.Form form = headerForm.getForm().getForm();
headerForm.getToolkit().decorateFormHeading(form);
// Create a composite for the overall head layout.
Composite headClient = new Composite(form.getHead(), SWT.NONE);
// Set the layout to a GridLayout. It will contain separate columns for
// the description and, if applicable, process widgets (a label, a
// dropdown, and go/cancel buttons).
GridLayout gridLayout = new GridLayout(1, false);
headClient.setLayout(gridLayout);
// Create a label to take up the first space and provide the
// description of the Form.
Label descLabel = new Label(headClient, SWT.WRAP);
descLabel.setText(iceDataForm.getDescription());
// Create the GridData for the label. It must take up all of the
// available horizontal space, but capable of shrinking down to the
// minimum width.
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
// For the minimum width, pick a length based on the average character
// width with the label's font. Use, say, 35 characters.
GC gc = new GC(descLabel);
int widthOf50Chars = gc.getFontMetrics().getAverageCharWidth() * 35;
gc.dispose();
// We set the min width so the label won't shrink below that width. We
// set the width hint to the same value so the widget won't compute its
// size base on SWT.DEFAULT (if this is the case, it won't wrap).
gridData.minimumWidth = widthOf50Chars;
gridData.widthHint = widthOf50Chars;
descLabel.setLayoutData(gridData);
// Create the process label, button and dropdown if the action list is
// available.
if (iceDataForm.getActionList() != null
&& !iceDataForm.getActionList().isEmpty()) {
// Create a label for the process buttons
Label processLabel = new Label(headClient, SWT.NONE);
processLabel.setText("Process:");
// Create the dropdown menu
processDropDown = new Combo(headClient, SWT.DROP_DOWN | SWT.SINGLE
| SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
for (String i : iceDataForm.getActionList()) {
processDropDown.add(i);
}
// Set the default process
processName = iceDataForm.getActionList().get(0);
processDropDown.select(0);
// Add the dropdown listener
processDropDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Set the action value to use when processing
processName = processDropDown.getItem(processDropDown
.getSelectionIndex());
}
});
// Create the button to process the Form
goButton = new Button(headClient, SWT.PUSH);
goButton.setText("Go!");
// Set the button's listener and process command
goButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Process the Form
notifyProcessListeners(processName);
}
});
// Create the button to cancel the process
cancelButton = new Button(headClient, SWT.PUSH);
cancelButton.setText("Cancel");
// Set the button's listener and process command
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Process the Form
notifyCancelListeners(processName);
}
});
// Since we have more widgets, add more columns to the GridLayout.
// All of these new widgets should grab what horizontal space they
// need but be vertically centered.
gridLayout.numColumns += 4;
gridData = new GridData(SWT.FILL, SWT.CENTER, false, true);
processLabel.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.CENTER, false, true);
processDropDown.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.CENTER, false, true);
goButton.setLayoutData(gridData);
gridData = new GridData(SWT.FILL, SWT.CENTER, false, true);
cancelButton.setLayoutData(gridData);
}
// Set the processComposite as the Form's head client
form.setHeadClient(headClient);
// Set Form name
form.setText(iceDataForm.getName() + " " + iceDataForm.getId());
return;
}
/**
* This operation creates a set of ICESectionPages using DataComponents,
* TableComponents, and MatrixComponents. These pages are used in the
* addPages() operation and rendered to the screen.
*
* @return
*/
protected ArrayList<ICEFormPage> createDataTableAndMatrixComponentPages() {
// Local Declarations
ArrayList<ICEFormPage> sectionPages = new ArrayList<ICEFormPage>();
ArrayList<Component> comps = new ArrayList<Component>();
ICESectionPage tmpPage = null;
String pageName = null;
int numCompsPerPage = 4, i = 0, j = 0;
int numComponents = 0;
// Get the TableComponents and DataComponents
comps.addAll(componentMap.get("data"));
comps.addAll(componentMap.get("table"));
comps.addAll(componentMap.get("matrix"));
numComponents = comps.size();
// If there are less components than the allowed number of components
// per page, just add them all to the first page
if (numComponents < numCompsPerPage) {
// Set a name for the page that is a combination of the first two
// components or only the first one if there is but one component
if (numComponents == 1) {
pageName = ((ICEObject) (comps.get(0))).getName();
} else {
pageName = ((ICEObject) (comps.get(0))).getName() + ", "
+ ((ICEObject) (comps.get(1))).getName() + ", etc.";
}
// Instantiate the page
tmpPage = new ICESectionPage(this, pageName, pageName);
// Loop over the list of DataComponents and create pages for them
for (Component component : comps) {
tmpPage.addComponent(component);
}
sectionPages.add(tmpPage);
} else {
// Otherwise, if there are more components than the number of
// components per page, add them all with numCompsPerPage Components
// per page. This loop adds all of the full pages.
for (i = 0; i < (numComponents / numCompsPerPage) * numCompsPerPage; i = i
+ numCompsPerPage) {
// Set a name for the page that is a combination of the first
// two components
pageName = ((ICEObject) (comps.get(i))).getName() + ", "
+ ((ICEObject) (comps.get(i + 1))).getName() + ", etc.";
// Create the page
tmpPage = new ICESectionPage(this, pageName, pageName);
// Add the components
for (j = 0; j < numCompsPerPage; j++) {
// i - 1 + j is the buffer offset
tmpPage.addComponent(comps.get(i + j));
}
// Add the page to the list
sectionPages.add(tmpPage);
}
// Clean up the left over components by just adding them to
// their own page.
if (i != comps.size()) {
// Start by adding setting up the name
if (comps.size() - i == 1) {
pageName = ((ICEObject) (comps.get(i))).getName();
} else {
pageName = ((ICEObject) (comps.get(i))).getName() + ", "
+ ((ICEObject) (comps.get(i + 1))).getName()
+ ", etc.";
}
// Create the page
tmpPage = new ICESectionPage(this, pageName, pageName);
// Add the components
while (i < comps.size()) {
tmpPage.addComponent(comps.get(i));
i++;
}
// Add the page to the list
sectionPages.add(tmpPage);
}
}
return sectionPages;
}
/**
* This operation overrides init so that the ICE Form, passed as an
* IEditorInput, can be stored.
*/
@Override
public void init(IEditorSite site, IEditorInput input) {
// Check the input and throw an error if the type is wrong
if (!(input instanceof ICEFormInput)) {
throw new RuntimeException("Input passed to ICEFormEditor.init()"
+ " is not of type ICEFormInput.");
}
// Grab the Form and set the part name
ICEFormInput = (ICEFormInput) input;
iceDataForm = ICEFormInput.getForm();
setPartName(input.getName());
// Set the site
setSite(site);
// Set the input
setInput(input);
return;
}
/**
* This operation overrides isDirty to report the dirty state of the
* FormEditor.
*/
@Override
public boolean isDirty() {
return dirty;
}
/**
* This operation overrides the createToolkit operation to create the proper
* toolkit for an ICEFormEditor.
*
* @see org.eclipse.ui.forms.editor.FormEditor#createToolkit(org.eclipse.swt.widgets.Display)
*/
@Override
protected FormToolkit createToolkit(Display display) {
// Create and return the toolkit
return new FormToolkit(display);
}
/**
* (non-Javadoc)
*
* @see org.eclipse.ui.ISaveablePart#doSave(IProgressMonitor monitor)
*/
public void doSave(IProgressMonitor monitor) {
// Set the dirty flag
setDirty(false);
// Do the update
notifyUpdateListeners();
// Check the Form and enable the process button if the Form is ready
if (iceDataForm.isReady() && goButton != null) {
goButton.setEnabled(iceDataForm.isReady());
}
// Refresh the parts on the selected page
for (IFormPart part : ((ICEFormPage) this.getSelectedPage())
.getManagedForm().getParts()) {
part.refresh();
}
// Refresh the TreeCompositeViewer
if (!(componentMap.get("tree").isEmpty())) {
setTreeCompositeViewerInput();
}
// Refresh the MasterDetailsComponent
if (!(componentMap.get("masterDetails").isEmpty())) {
// Get the first MasterDetailsComponent (The current code only
// allows one master details to be implemented at this time
MasterDetailsComponent comp = (MasterDetailsComponent) (componentMap
.get("masterDetails").get(0));
// Get the name of the component
String name = comp.getName();
// Iterate over the pages of this editor to grab the
// MasterDetailsPage
for (int i = 0; i < this.getPageCount(); i++) {
// Get the page
FormPage formPage = (FormPage) this.pages.get(i);
// If the formPage has the same name as the masterDetails, then
// it is the masterDetails page (it is stored this way!)
if (formPage.getPartName().equals(name)) {
// Cast it as a MasterDetailsPage
ICEMasterDetailsPage masterPage = (ICEMasterDetailsPage) formPage;
// Refresh the master
masterPage.refreshMaster();
}
}
}
// Refresh the EMF pages
if (!(componentMap.get("emf")).isEmpty()) {
for (int i = 0; i < this.getPageCount(); i++) {
FormPage formPage = (FormPage) this.pages.get(i);
EMFComponent comp = (EMFComponent) componentMap.get("emf").get(
0);
if (formPage.getPartName().equals(comp.getName())) {
formPage.doSave(null);
}
}
}
}
/**
* (non-Javadoc)
*
* @see org.eclipse.ui.ISaveablePart#doSaveAs()
*/
public void doSaveAs() {
// Just save
doSave(null);
return;
}
/**
* (non-Javadoc)
*
* @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
*/
public boolean isSaveAsAllowed() {
return false;
}
/**
* (non-Javadoc)
*
* @see FormEditor#addPages()
*/
protected void addPages() {
// Local Declaration
ArrayList<ICEFormPage> formPages = new ArrayList<ICEFormPage>();
// Loop over the DataComponents and get them into the map
for (Component i : iceDataForm.getComponents()) {
System.out.println("ICEFormEditor Message: Adding component "
+ i.getName() + " " + i.getId());
i.accept(this);
}
// Create pages for the DataComponents and add them to the list
if (!(componentMap.get("data").isEmpty())
|| !(componentMap.get("table").isEmpty())
|| !(componentMap.get("matrix").isEmpty())) {
formPages.addAll(createDataTableAndMatrixComponentPages());
}
// Create pages for the MasterDetailsComponents
if (!(componentMap.get("masterDetails").isEmpty())) {
formPages.addAll(createMasterDetailsComponentPages());
}
// Create the page for GeometryComponents
if (!(componentMap.get("geometry").isEmpty())) {
formPages.add(createGeometryPage());
}
// Create the page for MeshComponents
if (!(componentMap.get("mesh").isEmpty())) {
formPages.add(createMeshPage());
}
// Create pages for the EMF components
if (componentMap.get("emf").size() > 0) {
for (ICEFormPage p : createEMFSectionPages()) {
formPages.add(p);
}
}
// Create pages for list components
if (componentMap.get("list").size() > 0) {
for (ICEFormPage p : createListSectionPages()) {
formPages.add(p);