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