f360d50fd872c2baf9788369a452a4595e2f1333
[Mograsim.git] /
1 package net.mograsim.plugin.wizards.newWizards;
2
3 import org.eclipse.jface.dialogs.Dialog;
4 import org.eclipse.jface.viewers.IStructuredSelection;
5 import org.eclipse.jface.wizard.WizardPage;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.layout.GridData;
8 import org.eclipse.swt.layout.GridLayout;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Label;
11
12 import net.mograsim.plugin.nature.MachineContextSwtTools;
13 import net.mograsim.plugin.nature.MachineContextSwtTools.MachineCombo;
14
15 public class MograsimSettingsPage extends WizardPage
16 {
17         private MachineCombo machineSelect;
18         private Label machineDescription;
19
20         public MograsimSettingsPage(IStructuredSelection selection)
21         {
22                 this();
23         }
24
25         public MograsimSettingsPage()
26         {
27                 super("Mograsim Project Settings");
28                 setPageComplete(false);
29         }
30
31         @Override
32         public void createControl(Composite parent)
33         {
34                 Composite composite = new Composite(parent, SWT.NULL);
35                 initializeDialogUnits(parent);
36
37                 composite.setLayout(new GridLayout());
38                 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
39
40                 addFirstSection(composite);
41                 addSeparator(composite);
42                 addSecondSection(composite);
43
44                 // Show description on opening
45                 setErrorMessage(null);
46                 setMessage(null);
47                 setControl(composite);
48                 Dialog.applyDialogFont(composite);
49         }
50
51         private void addFirstSection(Composite parent)
52         {
53                 Composite composite = createDefaultComposite(parent, false);
54
55                 // Label for path field
56                 Label pathLabel = new Label(composite, SWT.NONE);
57                 pathLabel.setText("Please configure the machine that Mograsim should use:");
58         }
59
60         private void addSeparator(Composite parent)
61         {
62                 Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
63                 GridData gridData = new GridData();
64                 gridData.horizontalAlignment = GridData.FILL;
65                 gridData.grabExcessHorizontalSpace = true;
66                 separator.setLayoutData(gridData);
67         }
68
69         private Composite createDefaultComposite(Composite parent, boolean grabExcessVerticalSpace)
70         {
71                 Composite composite = new Composite(parent, SWT.NULL);
72                 GridLayout layout = new GridLayout();
73                 layout.numColumns = 2;
74                 composite.setLayout(layout);
75
76                 GridData data = new GridData();
77                 data.verticalAlignment = GridData.FILL;
78                 data.horizontalAlignment = GridData.FILL;
79                 data.grabExcessHorizontalSpace = true;
80                 data.grabExcessVerticalSpace = grabExcessVerticalSpace;
81                 composite.setLayoutData(data);
82
83                 return composite;
84         }
85
86         private void addSecondSection(Composite parent)
87         {
88                 Composite composite = createDefaultComposite(parent, true);
89
90                 // Label for machine
91                 Label ownerLabel = new Label(composite, SWT.NONE);
92                 ownerLabel.setText("Machine definition");
93
94                 // Machine choice
95                 machineSelect = MachineContextSwtTools.createMachineSelector(composite, SWT.NONE);
96                 machineSelect.addListener(md -> setPageComplete(isValid()));
97
98                 machineDescription = new Label(composite, SWT.NONE);
99                 machineSelect.addListener(md -> machineDescription.setText(md.getDescription()));
100                 machineDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
101         }
102
103         public boolean isValid()
104         {
105                 return machineSelect.isValidSelection();
106         }
107
108         @Override
109         public void setVisible(boolean visible)
110         {
111                 super.setVisible(visible);
112                 if (visible)
113                 {
114 //                      machineSelect.getCombo().getCCombo().setFocus();
115                 }
116         }
117
118         public final MograsimProjectConfig getMograsimProjectConfig()
119         {
120                 return new MograsimProjectConfig(machineSelect.getSelection().getId());
121         }
122
123         public static final class MograsimProjectConfig
124         {
125                 final String machineId;
126
127                 public MograsimProjectConfig(String machineId)
128                 {
129                         this.machineId = machineId;
130                 }
131
132                 public final String getMachineId()
133                 {
134                         return machineId;
135                 }
136         }
137 }