X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMainMachineLaunchConfigTab.java;h=3072c8aa48dcae40d02af972139f0407b1de517c;hb=18a120638da6387fbc895f30c64fb570b8d51cae;hp=68baf2f768703e7b90cfaff0c11d96975529ccc1;hpb=da1a7df25582ae1fe277762c2ba5640d4697a71c;p=Mograsim.git 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..3072c8aa 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 @@ -27,7 +27,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; @@ -43,6 +43,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { private Text projSelText; private Text mpmFileSelText; + private Text initialRAMFileSelText; @Override public void createControl(Composite parent) @@ -51,37 +52,40 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab Composite innerParent = new Composite(parent, SWT.NONE); setControl(innerParent); - innerParent.setLayout(new GridLayout()); + innerParent.setLayout(new GridLayout(3, false)); - this.projSelText = createResourceSelectorGroup(innerParent, this::chooseMograsimProject); + this.projSelText = addResourceSelector(innerParent, "&Project:", this::chooseMograsimProject); - this.mpmFileSelText = createResourceSelectorGroup(innerParent, this::chooseMPMFile); + this.mpmFileSelText = addResourceSelector(innerParent, "&MPM:", this::chooseMPMFile); - // TODO RAM selector + this.initialRAMFileSelText = addResourceSelector(innerParent, "Initial &RAM (optional):", this::chooseInitialRAMFile); } - private Text createResourceSelectorGroup(Composite innerParent, Supplier chooser) + private Text addResourceSelector(Composite innerParent, String label, 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); + Label swtLabel = new Label(innerParent, SWT.NONE); + swtLabel.setText(label); + swtLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + + Text text = new Text(innerParent, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + text.addModifyListener(e -> updateLaunchConfigurationDialog()); + + swtLabel.addListener(SWT.FocusIn, e -> text.setFocus()); + + Button browseButton = new Button(innerParent, 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) @@ -120,6 +124,8 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab } }; ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), renderer, new WorkbenchContentProvider()); + dialog.setTitle("MPM Selection"); + dialog.setMessage("Select a MPM file"); dialog.setInput(getSelectedProject()); dialog.addFilter(new FileExtensionViewerFilter("mpm")); @@ -128,6 +134,27 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab return null; } + private String chooseInitialRAMFile() + { + WorkbenchLabelProvider renderer = new WorkbenchLabelProvider() + { + @Override + protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) + { + return new ImageDescriptorWithMargins(input, new Point(22, 16)); + } + }; + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), renderer, new WorkbenchContentProvider()); + dialog.setTitle("Initial RAM Selection"); + dialog.setMessage("Select a RAM file"); + dialog.setInput(getSelectedProject()); + dialog.addFilter(new FileExtensionViewerFilter("mem")); + + if (dialog.open() == Window.OK) + return ((IResource) dialog.getResult()[0]).getProjectRelativePath().toPortableString(); + return null; + } + private IProject getSelectedProject() { String projName = projSelText.getText().trim(); @@ -161,16 +188,22 @@ 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, "")); + initialRAMFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.INITIAL_RAM_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 @@ -178,6 +211,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { String projName = projSelText.getText().trim(); String mpmFileName = mpmFileSelText.getText().trim(); + String initialRAMFileName = initialRAMFileSelText.getText().trim(); Set associatedResources = new HashSet<>(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); @@ -188,11 +222,15 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { if (project != null && project.isAccessible() && project.hasNature(MograsimNature.NATURE_ID)) { + associatedResources.add(project); + IResource mpmFile = project.findMember(mpmFileName); if (mpmFile != null && mpmFile.exists() && mpmFile.getType() == IResource.FILE) associatedResources.add(mpmFile); - else - associatedResources.add(project); + + IResource ramFile = project.findMember(initialRAMFileName); + if (ramFile != null && ramFile.exists() && ramFile.getType() == IResource.FILE) + associatedResources.add(ramFile); } } catch (CoreException e) @@ -203,6 +241,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab configuration.setMappedResources(associatedResources.toArray(IResource[]::new)); configuration.setAttribute(MachineLaunchConfigType.PROJECT_ATTR, projName); configuration.setAttribute(MachineLaunchConfigType.MPM_FILE_ATTR, mpmFileName); + configuration.setAttribute(MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, initialRAMFileName); } @Override @@ -243,6 +282,16 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab if (mpmResource.getType() != IResource.FILE) return setErrorAndReturnFalse("MPM file {0} is not a file", mpmFileName); + String initialRAMFileName = initialRAMFileSelText.getText().trim(); + if (initialRAMFileName.length() > 0) + { + IResource initialRAMResource = project.findMember(initialRAMFileName); + if (initialRAMResource == null || !initialRAMResource.exists()) + return setErrorAndReturnFalse("Initial RAM file {0} does not exist", initialRAMFileName); + if (initialRAMResource.getType() != IResource.FILE) + return setErrorAndReturnFalse("Initial RAM file {0} is not a file", initialRAMFileName); + } + return true; }