From 7c4c7e6087e3d3282851dfcd722aa237afcd8e2a Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Sun, 29 Sep 2019 23:10:03 +0200 Subject: [PATCH] MPM file gets loaded when MainMachineLaunchConfigTab is created --- .../launch/MainMachineLaunchConfigTab.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java index 68baf2f7..6f3c2937 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java @@ -53,35 +53,37 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab innerParent.setLayout(new GridLayout()); - this.projSelText = createResourceSelectorGroup(innerParent, this::chooseMograsimProject); + this.projSelText = createResourceSelectorGroup(innerParent, "&Project:", this::chooseMograsimProject); - this.mpmFileSelText = createResourceSelectorGroup(innerParent, this::chooseMPMFile); + this.mpmFileSelText = createResourceSelectorGroup(innerParent, "&MPM:", this::chooseMPMFile); // TODO RAM selector } - private Text createResourceSelectorGroup(Composite innerParent, Supplier chooser) + private Text createResourceSelectorGroup(Composite innerParent, String groupName, Supplier chooser) { - Group projSelGroup = new Group(innerParent, SWT.NONE); - projSelGroup.setLayout(new GridLayout(2, false)); - projSelGroup.setText("&Project:"); - projSelGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - Text projSelText = new Text(projSelGroup, SWT.BORDER); - projSelText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - projSelText.addModifyListener(e -> updateLaunchConfigurationDialog()); - Button projSelButton = new Button(projSelGroup, SWT.PUSH); + Group group = new Group(innerParent, SWT.NONE); + group.setLayout(new GridLayout(2, false)); + group.setText(groupName); + group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + Text text = new Text(group, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + text.addModifyListener(e -> updateLaunchConfigurationDialog()); + + Button browseButton = new Button(group, SWT.PUSH); GridData projSelButtonData = new GridData(); - projSelButtonData.widthHint = calculateWidthHint(projSelButton); + projSelButtonData.widthHint = calculateWidthHint(browseButton); projSelButtonData.horizontalAlignment = SWT.FILL; - projSelButton.setLayoutData(projSelButtonData); - projSelButton.setText("&Browse..."); - projSelButton.addListener(SWT.Selection, e -> + browseButton.setLayoutData(projSelButtonData); + browseButton.setText("&Browse..."); + browseButton.addListener(SWT.Selection, e -> { String chosen = chooser.get(); if (chosen != null) - projSelText.setText(chosen); + text.setText(chosen); }); - return projSelText; + return text; } private static int calculateWidthHint(Control c) @@ -161,16 +163,21 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab @Override public void initializeFrom(ILaunchConfiguration configuration) { - String projName = ""; + projSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.PROJECT_ATTR, "")); + mpmFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.MPM_FILE_ATTR, "")); + } + + private String getStringAttribSafe(ILaunchConfiguration configuration, String attrib, String defaultValue) + { try { - projName = configuration.getAttribute(MachineLaunchConfigType.PROJECT_ATTR, ""); + return configuration.getAttribute(attrib, defaultValue); } catch (CoreException e) { setErrorMessage(e.getStatus().getMessage()); } - projSelText.setText(projName); + return defaultValue; } @Override -- 2.17.1