X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMainMachineLaunchConfigTab.java;h=fbbe2640f249bcea52cb4a05ef9829afbdfc8100;hb=b5d55c59d7069171bd928e4a945d9185ee4bc2b0;hp=7671827d8bbd900bc3bb1587ec59689a9e58e46e;hpb=d8d92dba4339e1240e4362046eadbe51c6740780;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 7671827d..fbbe2640 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; @@ -37,12 +37,14 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; import net.mograsim.plugin.nature.MograsimNature; import net.mograsim.plugin.util.FileExtensionViewerFilter; import net.mograsim.plugin.util.ImageDescriptorWithMargins; +import net.mograsim.plugin.util.ProjectViewerFilter; //a big part of this class is stolen from org.eclipse.jdt.debug.ui public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { private Text projSelText; private Text mpmFileSelText; + private Text mpromFileSelText; private Text initialRAMFileSelText; @Override @@ -52,27 +54,30 @@ 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, "&Project:", this::chooseMograsimProject); + this.projSelText = addResourceSelector(innerParent, "P&roject:", this::chooseMograsimProject); - this.mpmFileSelText = createResourceSelectorGroup(innerParent, "&MPM:", this::chooseMPMFile); + this.mpmFileSelText = addResourceSelector(innerParent, "&MPM:", this::chooseMPMFile); - this.initialRAMFileSelText = createResourceSelectorGroup(innerParent, "Initial &RAM (optional):", this::chooseInitialRAMFile); + this.mpromFileSelText = addResourceSelector(innerParent, "M&PROM:", this::chooseMPROMFile); + + this.initialRAMFileSelText = addResourceSelector(innerParent, "Initial &RAM (optional):", this::chooseInitialRAMFile); } - private Text createResourceSelectorGroup(Composite innerParent, String groupName, Supplier chooser) + private Text addResourceSelector(Composite innerParent, String label, Supplier chooser) { - 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)); + Label swtLabel = new Label(innerParent, SWT.NONE); + swtLabel.setText(label); + swtLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); - Text text = new Text(group, SWT.BORDER); + Text text = new Text(innerParent, SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); text.addModifyListener(e -> updateLaunchConfigurationDialog()); - Button browseButton = new Button(group, SWT.PUSH); + swtLabel.addListener(SWT.FocusIn, e -> text.setFocus()); + + Button browseButton = new Button(innerParent, SWT.PUSH); GridData projSelButtonData = new GridData(); projSelButtonData.widthHint = calculateWidthHint(browseButton); projSelButtonData.horizontalAlignment = SWT.FILL; @@ -95,12 +100,13 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab private String chooseMograsimProject() { + // TODO this seems very ugly, especially hardcoded width/height WorkbenchLabelProvider renderer = new WorkbenchLabelProvider() { @Override protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) { - return new ImageDescriptorWithMargins(input, new Point(22, 16)); + return new ImageDescriptorWithMargins(input, new Point(20, 16)); } }; ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), renderer); @@ -114,40 +120,28 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab private String chooseMPMFile() { - 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("MPM Selection"); - dialog.setMessage("Select a MPM file"); - dialog.setInput(getSelectedProject()); - dialog.addFilter(new FileExtensionViewerFilter("mpm")); + return chooseFile("MPM", "mpm"); + } - if (dialog.open() == Window.OK) - return ((IResource) dialog.getResult()[0]).getProjectRelativePath().toPortableString(); - return null; + private String chooseMPROMFile() + { + return chooseFile("MPROM", "mprom"); } 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")); + return chooseFile("Initial RAM", "mem"); + } + + private String chooseFile(String type, String fileext) + { + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), + new WorkbenchContentProvider()); + dialog.setTitle(type + " Selection"); + dialog.setMessage("Select a ." + fileext + " file"); + dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); + dialog.addFilter(new FileExtensionViewerFilter(fileext)); + dialog.addFilter(new ProjectViewerFilter(getSelectedProject())); if (dialog.open() == Window.OK) return ((IResource) dialog.getResult()[0]).getProjectRelativePath().toPortableString(); @@ -189,6 +183,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { projSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.PROJECT_ATTR, "")); mpmFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.MPM_FILE_ATTR, "")); + mpromFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.MPROM_FILE_ATTR, "")); initialRAMFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, "")); } @@ -210,6 +205,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { String projName = projSelText.getText().trim(); String mpmFileName = mpmFileSelText.getText().trim(); + String mpromFileName = mpromFileSelText.getText().trim(); String initialRAMFileName = initialRAMFileSelText.getText().trim(); Set associatedResources = new HashSet<>(); @@ -227,6 +223,10 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab if (mpmFile != null && mpmFile.exists() && mpmFile.getType() == IResource.FILE) associatedResources.add(mpmFile); + IResource mpromFile = project.findMember(mpromFileName); + if (mpromFile != null && mpromFile.exists() && mpromFile.getType() == IResource.FILE) + associatedResources.add(mpromFile); + IResource ramFile = project.findMember(initialRAMFileName); if (ramFile != null && ramFile.exists() && ramFile.getType() == IResource.FILE) associatedResources.add(ramFile); @@ -240,6 +240,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.MPROM_FILE_ATTR, mpromFileName); configuration.setAttribute(MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, initialRAMFileName); } @@ -281,6 +282,16 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab if (mpmResource.getType() != IResource.FILE) return setErrorAndReturnFalse("MPM file {0} is not a file", mpmFileName); + String mpromFileName = mpromFileSelText.getText().trim(); + if (mpromFileName.length() > 0) + { + IResource mpromResource = project.findMember(mpromFileName); + if (mpromResource == null || !mpromResource.exists()) + return setErrorAndReturnFalse("MPROM file {0} does not exist", mpromFileName); + if (mpromResource.getType() != IResource.FILE) + return setErrorAndReturnFalse("MPROM file {0} is not a file", mpromFileName); + } + String initialRAMFileName = initialRAMFileSelText.getText().trim(); if (initialRAMFileName.length() > 0) { @@ -303,6 +314,6 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab @Override public String getName() { - return "testlaunchconfigtabname"; + return "Main"; } } \ No newline at end of file