X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2Fproperties%2FMograsimNaturePropertyPage.java;h=1b6c3d8e3faad5d2e4fe4a2553161024864a572f;hb=161ecd36b6dcfe0e38cee3fd6ea8ad42d0705777;hp=edf07e2c3a6d56461dee75af546fea6d7195a5de;hpb=363c9377b3c542c87fc5e7f57674751439246dbd;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/properties/MograsimNaturePropertyPage.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/properties/MograsimNaturePropertyPage.java index edf07e2c..1b6c3d8e 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/properties/MograsimNaturePropertyPage.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/properties/MograsimNaturePropertyPage.java @@ -6,26 +6,29 @@ import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.dialogs.PropertyPage; +import net.mograsim.machine.MachineDefinition; import net.mograsim.machine.MachineRegistry; import net.mograsim.plugin.nature.MachineContext; +import net.mograsim.plugin.nature.MachineContextSwtTools; +import net.mograsim.plugin.nature.MachineContextSwtTools.MachineCombo; import net.mograsim.plugin.nature.ProjectMachineContext; public class MograsimNaturePropertyPage extends PropertyPage { - + // TODO i10n private static final String WARNING = "Changing the Mograsim machine can completely break your project. Be careful."; - private static final String MACHINE_LABEL = "Machine ID"; + private static final String MACHINE_LABEL = "Machine definition"; private static final String MACHINE_PROPERTY = "net.mograsim.projectMachineId"; - private static final String DEFAULT_MACHINE = "Am2900"; + private static final String DEFAULT_MACHINE = "Am2900Teaching";// TODO don't hardcode that here! - private Combo machineSelect; - private String defaultId; + private MachineCombo machineSelect; + private Label machineDescription; + private MachineDefinition defaultMachineDefinition; private MachineContext machineContext; @@ -39,7 +42,7 @@ public class MograsimNaturePropertyPage extends PropertyPage private void addFirstSection(Composite parent) { - Composite composite = createDefaultComposite(parent); + Composite composite = createDefaultComposite(parent, false); // Label for path field Label pathLabel = new Label(composite, SWT.NONE); @@ -57,32 +60,25 @@ public class MograsimNaturePropertyPage extends PropertyPage private void addSecondSection(Composite parent) { - Composite composite = createDefaultComposite(parent); + Composite composite = createDefaultComposite(parent, true); // Label for machine Label ownerLabel = new Label(composite, SWT.NONE); ownerLabel.setText(MACHINE_LABEL); // Machine choice - machineSelect = new Combo(parent, SWT.BORDER); - GridData gd = new GridData(); - machineSelect.setLayoutData(gd); - - Optional currentId = machineContext.getMachineId(); + machineSelect = MachineContextSwtTools.createMachineSelector(composite, SWT.NONE); - if (currentId.isPresent()) - machineSelect.add(currentId.get()); + machineDescription = new Label(composite, SWT.WRAP); + machineSelect.addListener(md -> machineDescription.setText(md.getDescription())); + machineDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - for (String machineId : MachineRegistry.getInstalledMachines().keySet()) - { - if (currentId.isPresent() && currentId.get().equals(machineId)) - continue; - machineSelect.add(machineId); - } + Optional currentMachineDefinition = machineContext.getMachineDefinition(); - defaultId = currentId.orElse(DEFAULT_MACHINE); + if (currentMachineDefinition.isPresent()) + machineSelect.setSelection(currentMachineDefinition.get()); - machineSelect.select(machineSelect.indexOf(defaultId)); + defaultMachineDefinition = currentMachineDefinition.orElseGet(() -> MachineRegistry.getMachine(DEFAULT_MACHINE)); } /** @@ -105,7 +101,7 @@ public class MograsimNaturePropertyPage extends PropertyPage return composite; } - private Composite createDefaultComposite(Composite parent) + private Composite createDefaultComposite(Composite parent, boolean grabExcessVerticalSpace) { Composite composite = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); @@ -115,6 +111,8 @@ public class MograsimNaturePropertyPage extends PropertyPage GridData data = new GridData(); data.verticalAlignment = GridData.FILL; data.horizontalAlignment = GridData.FILL; + data.grabExcessHorizontalSpace = true; + data.grabExcessVerticalSpace = grabExcessVerticalSpace; composite.setLayoutData(data); return composite; @@ -124,14 +122,12 @@ public class MograsimNaturePropertyPage extends PropertyPage { super.performDefaults(); // Populate the owner text field with the default value - machineSelect.select(machineSelect.indexOf(DEFAULT_MACHINE)); + machineSelect.setSelection(defaultMachineDefinition); } public boolean performOk() { - int selected = machineSelect.getSelectionIndex(); - String newId = machineSelect.getItem(selected); - return machineContext.setMachineId(newId); + return machineContext.setMachineId(machineSelect.getSelection().getId()); } } \ No newline at end of file